Initial commit
This commit is contained in:
76
app_code/lib/helpers/common_functions.dart
Normal file
76
app_code/lib/helpers/common_functions.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grostore/custom_classes/system_data.dart';
|
||||
import 'package:grostore/helpers/shared_value_helper.dart';
|
||||
import 'package:grostore/presenters/main_persenter.dart';
|
||||
import 'package:grostore/screens/main.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
// bool isEmail(String input){
|
||||
// return RegExp(r'^.+@[a-zA-Z]+\.{1}[a-zA-Z]+(\.{0,1}[a-zA-Z]+)$').hasMatch(input);
|
||||
// }
|
||||
|
||||
resetApp(BuildContext context){
|
||||
Provider.of<MainPresenter>(context, listen: false).dispose();
|
||||
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context)=>Main()), (route) => false);
|
||||
}
|
||||
|
||||
getAssetImage(String img){
|
||||
return "assets/images/$img";
|
||||
}
|
||||
getAssetIcon(String icon){
|
||||
return "assets/icons/$icon";
|
||||
}
|
||||
String getAssetLogo(String logo){
|
||||
return "assets/logos/$logo";
|
||||
}
|
||||
getAssetFlag(String name){
|
||||
return "assets/flags/$name";
|
||||
}
|
||||
|
||||
|
||||
String getQueryParameter(BuildContext context , String key){
|
||||
String value = "";
|
||||
final path = ModalRoute.of(context);
|
||||
if(path !=null) {
|
||||
String url = path.settings.name!;
|
||||
List route = url.split("?");
|
||||
if (route.isNotEmpty && route[1] != "") {
|
||||
List qParameters = route[1].split("&");
|
||||
|
||||
qParameters.forEach((element) {
|
||||
List tmp = element.split("=");
|
||||
if (tmp.isNotEmpty && tmp[0]==key) {
|
||||
value = tmp[1];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
Map<String,String> getCurrencyHeader(){
|
||||
return system_currency.$.isNotEmpty?{
|
||||
"Currency-Code": system_currency.$
|
||||
}:{};
|
||||
}
|
||||
|
||||
Map<String,String> getCommonHeader(){
|
||||
return {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"App-Language": app_language.$,
|
||||
"Stock-Location-Id":stock_location_id.$
|
||||
};
|
||||
}
|
||||
|
||||
Map<String,String> getCouponHeader(){
|
||||
return {
|
||||
"Coupon-Code":SystemData.couponCode
|
||||
};
|
||||
}
|
||||
|
||||
String showPrice(String price){
|
||||
return price;
|
||||
//price.replaceAll(SystemData.systemCurrency?.code??"", SystemData.systemCurrency?.symbol??"");
|
||||
}
|
||||
8
app_code/lib/helpers/device_info_helper.dart
Normal file
8
app_code/lib/helpers/device_info_helper.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
double getWidth(context){
|
||||
return MediaQuery.of(context).size.width;
|
||||
}
|
||||
double getHeight(context){
|
||||
return MediaQuery.of(context).size.height;
|
||||
}
|
||||
39
app_code/lib/helpers/route.dart
Normal file
39
app_code/lib/helpers/route.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:grostore/presenters/cart_presenter.dart';
|
||||
import 'package:grostore/presenters/check_out_presenter.dart';
|
||||
import 'package:grostore/screens/product_details.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MakeRoute{
|
||||
static Navigator route = const Navigator();
|
||||
static go(BuildContext context,dynamic newRoute){
|
||||
Navigator.push(context, MaterialPageRoute<ProductDetails>(builder: (context)=>newRoute));
|
||||
|
||||
}
|
||||
static goAndRemoveAll(context,dynamic newRoute){
|
||||
MakeRoute.clearProviders(context);
|
||||
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context)=>newRoute),(route)=>false);
|
||||
}
|
||||
|
||||
static productRoute(BuildContext context,Widget route){
|
||||
|
||||
if(context.widget.runtimeType == ProductDetails){
|
||||
|
||||
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context)=>route));
|
||||
}else{
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context)=>route));
|
||||
}
|
||||
}
|
||||
static goName(BuildContext context, String route){
|
||||
Navigator.pushNamed( context, route);
|
||||
}
|
||||
|
||||
|
||||
static clearProviders(BuildContext context){
|
||||
Provider.of<CartPresenter>(context,listen: false).clearAll();
|
||||
Provider.of<CheckOutPresenter>(context,listen: false).clearAll();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
42
app_code/lib/helpers/shared_value_helper.dart
Normal file
42
app_code/lib/helpers/shared_value_helper.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
import 'package:shared_value/shared_value.dart';
|
||||
|
||||
final SharedValue<bool> show_landing_page = SharedValue(
|
||||
value: true, // initial value
|
||||
key: "show_landing_page",
|
||||
autosave: true// disk storage key for shared_preferences
|
||||
);
|
||||
|
||||
final SharedValue<String> access_token = SharedValue(
|
||||
value: "", // initial value
|
||||
key: "access_token",
|
||||
autosave: true// disk storage key for shared_preferences
|
||||
);
|
||||
final SharedValue<String> app_language = SharedValue(
|
||||
// initial value
|
||||
key: "app_mobile_language",
|
||||
value: "en",
|
||||
autosave: true
|
||||
);
|
||||
|
||||
final SharedValue<bool> language_is_rtl = SharedValue(
|
||||
// initial value
|
||||
key: "language_is_rtl",
|
||||
value: false,
|
||||
autosave: true
|
||||
);
|
||||
final SharedValue<String> server_app_language = SharedValue(
|
||||
value: "en", // initial value
|
||||
key: "server_app_language",
|
||||
autosave: true// disk storage key for shared_preferences
|
||||
);
|
||||
|
||||
final SharedValue<String> system_currency = SharedValue(
|
||||
key: "system_currency",
|
||||
value: '',
|
||||
);
|
||||
final SharedValue<String> stock_location_id = SharedValue(
|
||||
key: "stock_location_id",
|
||||
value: '',
|
||||
autosave: true,
|
||||
);
|
||||
6
app_code/lib/helpers/utils.dart
Normal file
6
app_code/lib/helpers/utils.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class Utils {
|
||||
static formatPrice(double price) => '\$ ${price.toStringAsFixed(2)}';
|
||||
static formatDate(DateTime date) => DateFormat.yMd().format(date);
|
||||
}
|
||||
Reference in New Issue
Block a user