You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
doctor_app_flutter/lib/util/helpers.dart

160 lines
4.5 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../config/size_config.dart';
import '../util/dr_app_toast_msg.dart';
import 'package:connectivity/connectivity.dart';
DrAppToastMsg toastMsg = DrAppToastMsg();
/*
*@author: Elham Rababah
*@Date:12/4/2020
*@param:
*@return:
*@desc: This class will contian some Function will help developer
*/
class Helpers {
int cupertinoPickerIndex = 0;
/*
*@author: Elham Rababah
*@Date:12/4/2020
*@param: context, items, decKey, onSelectFun
*@return: Container Widget
*@desc: showCupertinoPicker its a general function to show cupertino picker
*/
showCupertinoPicker(context, items, decKey, onSelectFun) {
showModalBottomSheet(
isDismissible: false,
context: context,
builder: (BuildContext builder) {
return Container(
// height: 500,
height: SizeConfig.realScreenHeight * 0.4,
color: Color(0xfff7f7f7),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
color: Color(0xfff7f7f7),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
CupertinoButton(
child: Text('Cancel'.toUpperCase(), style: textStyle(context)),
onPressed: () {
Navigator.pop(context);
},
// padding: const EdgeInsets.symmetric(
// horizontal: 16.0,
// vertical: 5.0,
// ),
),
CupertinoButton(
child: Text(
'Done'.toUpperCase(),
style: textStyle(context),
),
onPressed: () {
Navigator.pop(context);
onSelectFun(cupertinoPickerIndex);
},
)
],
),
),
Container(
height: SizeConfig.realScreenHeight * 0.3,
color: Color(0xfff7f7f7),
child:
buildPickerItems(context, items, decKey, onSelectFun))
],
),
);
});
}
TextStyle textStyle(context) =>
TextStyle(color: Theme.of(context).primaryColor);
/*
*@author: Elham Rababah
*@Date:12/4/2020
*@param: context, List items, decKey, onSelectFun
*@return: Container widget
*@desc: buildPickerIterm this function will build the items of the cupertino
*/
buildPickerItems(context, List items, decKey, onSelectFun) {
return CupertinoPicker(
magnification: 1.5,
scrollController: FixedExtentScrollController(initialItem: cupertinoPickerIndex),
// backgroundColor: Colors.black87,
children: items.map((item) {
return Text(
'${item["$decKey"]}',
style: TextStyle(fontSize: SizeConfig.textMultiplier * 3),
);
}).toList(),
itemExtent: 25, //height of each item
looping: true,
onSelectedItemChanged: (int index) {
// selectitem =index;
cupertinoPickerIndex = index;
},
);
}
/*
*@author: Elham Rababah
*@Date:12/4/2020
*@param: msg
*@return:
*@desc: showErrorToast
*/
showErrorToast([msg = null]) {
String localMsg = generateContactAdminMsg();
if (msg != null) {
localMsg = msg.toString();
}
toastMsg.showErrorToast(localMsg);
}
/*
*@author: Mohammad Aljammal
*@Date:27/4/2020
*@param:
*@return: Boolean
*@desc: Check The Internet Connection
*/
static Future<bool> checkConnection() async {
ConnectivityResult connectivityResult =
await (Connectivity().checkConnectivity());
if ((connectivityResult == ConnectivityResult.mobile) ||
(connectivityResult == ConnectivityResult.wifi)) {
return true;
} else {
return false;
}
}
/*
*@author: Elham Rababah
*@Date:12/5/2020
*@param:
*@return: String
*@desc: generate Contact Admin Msg
*/
generateContactAdminMsg([err = null]) {
String localMsg = 'Something wrong happened, please contact the admin';
if (err != null) {
localMsg = localMsg + '\n \n' + err.toString();
}
return localMsg;
}
}