Files
fcs/lib/pages/main/util.dart

398 lines
13 KiB
Dart
Raw Normal View History

2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:fcs/pages/widgets/local_text.dart';
2020-05-29 07:45:27 +06:30
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
2020-10-07 02:33:06 +06:30
import '../widgets/label_widgets.dart';
2020-05-29 07:45:27 +06:30
final log = Logger('Util');
2020-09-12 03:34:52 +06:30
Future showMsgDialog(BuildContext context, String title, String msg) {
return showDialog(
2020-05-29 07:45:27 +06:30
context: context,
builder: (_) {
return AlertDialog(
title: new Text(title),
content: new Text(msg),
actions: <Widget>[
2024-01-09 13:11:22 +06:30
new TextButton(
2024-01-25 17:40:35 +06:30
child: new Text(
"Close",
style: TextStyle(color: primaryColor),
),
2020-05-29 07:45:27 +06:30
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
Future<void> showConfirmDialog(
BuildContext context, String translationKey, ok(),
2021-09-10 12:00:08 +06:30
{List<String>? translationVariables}) async {
2020-05-29 07:45:27 +06:30
await showDialog(
context: context,
builder: (_) {
return AlertDialog(
title: Center(
child: LocalText(
context,
translationKey,
2021-09-13 09:52:36 +06:30
translationVariables: translationVariables,
2020-09-18 21:33:41 +06:30
color: primaryColor,
2020-05-29 07:45:27 +06:30
),
),
content: Container(
child: Row(
2020-09-15 07:13:41 +06:30
mainAxisAlignment: MainAxisAlignment.spaceAround,
2020-05-29 07:45:27 +06:30
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
2024-01-09 13:11:22 +06:30
TextButton(
2024-01-25 17:40:35 +06:30
style: TextButton.styleFrom(
backgroundColor: Colors.grey[300],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0))),
2020-05-29 07:45:27 +06:30
child: Text(
2021-09-10 14:25:37 +06:30
AppTranslations.of(context)!.text('btn.cancel'),
2020-05-29 07:45:27 +06:30
style: Provider.of<LanguageModel>(context).isEng
2024-01-25 17:40:35 +06:30
? TextStyle(color: primaryColor)
: TextStyle(
fontFamily: 'Myanmar3', color: primaryColor),
2020-05-29 07:45:27 +06:30
),
onPressed: () {
Navigator.of(context).pop();
}),
2020-09-15 07:13:41 +06:30
SizedBox(
width: 0,
),
2024-01-09 13:11:22 +06:30
TextButton(
2024-01-25 17:40:35 +06:30
style: TextButton.styleFrom(
backgroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0))),
2021-09-10 14:25:37 +06:30
child: Text(AppTranslations.of(context)!.text('btn.ok'),
2020-05-29 07:45:27 +06:30
style: Provider.of<LanguageModel>(context).isEng
? TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold)
: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
2020-10-07 02:33:06 +06:30
fontFamily: 'Myanmar3')),
2020-05-29 07:45:27 +06:30
onPressed: () async {
Navigator.of(context).pop();
await ok();
})
],
),
),
);
});
}
Widget getStatus(String status) {
2020-05-29 16:14:17 +06:30
return status == "Delivered"
2020-06-01 14:24:45 +06:30
? Text(status,
style: TextStyle(
color: primaryColor, fontSize: 18, fontWeight: FontWeight.bold))
2020-05-29 07:45:27 +06:30
: status == "rejected"
? Chip(
backgroundColor: Colors.red,
avatar: Icon(
Icons.remove,
color: Colors.white,
size: 14,
),
label: Text(
status,
style: TextStyle(color: Colors.white, fontSize: 12),
))
2020-05-29 16:14:17 +06:30
: status == "In progress"
2020-06-01 14:24:45 +06:30
? Text(
status,
style: TextStyle(color: Colors.white, fontSize: 12),
)
2020-05-31 15:00:11 +06:30
: status == "Pickuped"
2020-05-29 15:54:26 +06:30
? Text(
status,
2020-05-31 15:00:11 +06:30
style: TextStyle(
color: primaryColor,
fontSize: 18,
fontWeight: FontWeight.bold),
2020-05-29 15:54:26 +06:30
)
2020-05-31 15:00:11 +06:30
: status == "Pending" || status == "Rescheduled"
? Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(Icons.schedule),
),
Text(
status,
style: TextStyle(
color: primaryColor,
fontSize: 18,
fontWeight: FontWeight.bold),
)
],
2020-05-29 15:54:26 +06:30
)
2020-05-31 15:00:11 +06:30
: status == "Assigned"
? Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(Icons.check),
),
Text(
status,
style: TextStyle(
color: primaryColor,
fontSize: 18,
fontWeight: FontWeight.bold),
)
],
)
: status == "Canceled"
? Text(
status,
style: TextStyle(
color: primaryColor,
fontSize: 18,
fontWeight: FontWeight.bold),
)
2020-06-26 16:04:40 +06:30
: status == "Delivered" || status == "Avaliable"
2020-05-31 15:00:11 +06:30
? Text(
status,
style: TextStyle(
2020-06-26 16:04:40 +06:30
color: Colors.green, fontSize: 18),
2020-05-31 15:00:11 +06:30
)
2020-06-29 16:15:25 +06:30
: status == "Used"
2020-06-26 16:04:40 +06:30
? Text(
status,
style: TextStyle(
2020-06-29 16:15:25 +06:30
color: Colors.red, fontSize: 18),
2020-06-26 16:04:40 +06:30
)
: status == "Paid"
? Row(
children: <Widget>[
Padding(
padding:
const EdgeInsets.all(8.0),
child: Icon(Icons.check),
),
Text(
status,
style: TextStyle(
color: primaryColor,
fontSize: 18,
fontWeight:
FontWeight.bold),
)
],
)
: Text(
2021-09-10 12:00:08 +06:30
status,
2020-06-02 14:56:51 +06:30
style: TextStyle(
color: primaryColor,
fontSize: 18,
fontWeight: FontWeight.bold),
2020-06-26 16:04:40 +06:30
);
2020-05-29 07:45:27 +06:30
}
call(BuildContext context, String phone) {
showConfirmDialog(context, "contact.phone.confim", () => launch("tel:$phone"),
translationVariables: ["$phone"]);
}
2020-05-31 15:00:11 +06:30
Widget nameWidget(String name) {
return Center(
child: Padding(
padding: const EdgeInsets.only(left: 10.0, top: 8),
child: Text(
name,
style: TextStyle(
2020-06-26 16:04:40 +06:30
color: Colors.black87, fontSize: 18, fontWeight: FontWeight.bold),
2020-05-31 15:00:11 +06:30
),
),
);
}
Widget phoneWidget(BuildContext context, String phone) {
return Container(
padding: EdgeInsets.only(top: 10),
child: Row(
children: <Widget>[
Icon(Icons.phone),
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: labeledText(context, phone, "user.phone"),
),
],
),
);
}
Widget fcsInput(String label, IconData iconData,
2021-09-10 12:00:08 +06:30
{required TextEditingController controller,
required String value,
2020-09-13 21:49:39 +06:30
bool autoFocus = false,
2021-09-10 12:00:08 +06:30
TextInputType? textInputType}) {
2020-06-02 14:56:51 +06:30
return TextFormField(
initialValue: value,
controller: controller,
cursorColor: primaryColor,
maxLines: null,
minLines: 1,
2020-09-13 21:49:39 +06:30
autofocus: autoFocus,
keyboardType: textInputType,
2020-06-02 14:56:51 +06:30
decoration: InputDecoration(
fillColor: Colors.white,
labelText: label,
labelStyle: TextStyle(fontSize: 16, color: Colors.grey),
filled: true,
icon: Icon(
iconData,
2020-06-03 00:42:31 +06:30
color: primaryColor,
2020-06-02 14:56:51 +06:30
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 1.0)),
));
2020-05-31 15:00:11 +06:30
}
2020-06-01 14:42:42 +06:30
Widget fcsInputReadOnly(String label, IconData iconData,
2021-09-10 12:00:08 +06:30
{required TextEditingController controller, required String value}) {
2020-06-02 14:56:51 +06:30
return TextFormField(
initialValue: value,
controller: controller,
cursorColor: primaryColor,
maxLines: null,
minLines: 1,
2020-06-29 16:15:25 +06:30
readOnly: true,
2020-06-02 14:56:51 +06:30
decoration: InputDecoration(
fillColor: Colors.white,
border: InputBorder.none,
labelText: label,
labelStyle: TextStyle(fontSize: 16, color: Colors.grey),
filled: true,
icon: Icon(
iconData,
2020-08-30 21:26:37 +06:30
color: primaryColor,
2020-06-02 14:56:51 +06:30
),
));
2020-06-01 14:42:42 +06:30
}
2020-05-31 15:00:11 +06:30
Widget fcsDropDown(String label, IconData iconData,
2021-09-10 12:00:08 +06:30
{required TextEditingController controller}) {
2020-05-31 15:00:11 +06:30
return Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Icon(iconData),
),
Expanded(
child: Container(
height: 50.0,
child: Row(children: <Widget>[
Expanded(child: _dropDown()),
]),
)),
],
);
}
Widget _dropDown() {
return DropdownButton<String>(
value: "Ko Nge",
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
// style: TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: primaryColor,
),
2021-09-10 12:00:08 +06:30
onChanged: (String? newValue) {},
2020-05-31 15:00:11 +06:30
items: <String>['Ko Nge', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
);
}
2020-09-13 21:49:39 +06:30
Widget fcsButton(BuildContext context, String text,
2021-09-10 12:00:08 +06:30
{Function? callack, IconData? iconData}) {
2020-09-13 21:49:39 +06:30
var languageModel = Provider.of<LanguageModel>(context);
var style = languageModel.isEng
? TextStyle(
fontSize: 16.0, color: Colors.white, fontWeight: FontWeight.bold)
: TextStyle(
fontSize: 16.0,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: "Myanmar3");
2020-05-31 15:00:11 +06:30
return Container(
padding: EdgeInsets.only(left: 10, right: 10, top: 10),
child: SizedBox(
2020-05-31 15:00:11 +06:30
height: 45.0,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 0,
backgroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(3)))),
onPressed: callack == null ? null : () => callack(),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
iconData == null
? Container()
: Icon(
iconData,
color: Colors.white,
),
SizedBox(
width: 15,
),
Text(text, style: style),
],
2020-05-31 15:00:11 +06:30
),
),
),
);
}
2020-09-07 16:05:28 +06:30
2020-09-10 02:13:22 +06:30
String getLocalString(BuildContext context, String key) {
2021-09-10 14:25:37 +06:30
return AppTranslations.of(context)!.text(key);
2020-09-10 02:13:22 +06:30
}
2020-09-20 05:34:49 +06:30
void showToast(GlobalKey key, String text) {
2024-01-25 17:40:35 +06:30
final ScaffoldMessengerState scaffold =
key.currentState as ScaffoldMessengerState;
2020-09-20 05:34:49 +06:30
scaffold.showSnackBar(
SnackBar(
content: Text(text),
backgroundColor: secondaryColor,
duration: Duration(seconds: 1),
),
);
}
bool hasUnicode(String text) {
final int maxBits = 128;
List<int> unicodeSymbols =
text.codeUnits.where((ch) => ch > maxBits).toList();
return unicodeSymbols.length > 0;
}