import 'package:fcs/widget/label_widgets.dart'; import 'package:flutter/material.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart'; import 'package:logging/logging.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:fcs/model/announcement_model.dart'; import 'package:fcs/model/buyer_model.dart'; import 'package:fcs/model/do_model.dart'; import 'package:fcs/model/language_model.dart'; import 'package:fcs/model/notification_model.dart'; import 'package:fcs/model/po_model.dart'; import 'package:fcs/model/user_model.dart'; import 'package:fcs/theme/theme.dart'; import 'package:fcs/vo/buyer.dart'; import 'package:fcs/widget/local_text.dart'; import 'package:fcs/widget/localization/app_translations.dart'; import 'package:fcs/vo/notification.dart' as Noti; import 'announcement.dart'; import 'buyer_info.dart'; import 'do/do_approve.dart'; import 'log_list.dart'; import 'my_registeration_info.dart'; import 'po/po_submission_form.dart'; import 'products_list.dart'; import 'user_editor.dart'; final log = Logger('Util'); void showMsgDialog(BuildContext context, String title, String msg) { showDialog( context: context, builder: (_) { return AlertDialog( title: new Text(title), content: new Text(msg), actions: [ new FlatButton( child: new Text("Close"), onPressed: () { Navigator.of(context).pop(); }, ), ], ); }, ); } var selectedColor; void showColorPicker(BuildContext context, Color color, callback(Color color)) { showDialog( context: context, child: AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(32.0))), title: const Text('Pick product color'), content: SingleChildScrollView( child: ColorPicker( pickerColor: color.value == 0 ? Colors.red : color, pickerAreaHeightPercent: 0.6, onColorChanged: (Color value) { selectedColor = value; }, ), ), actions: [ FlatButton( child: const Text('Choose'), onPressed: () { callback(selectedColor == null ? Colors.red : selectedColor); Navigator.of(context).pop(); }, ), FlatButton( child: const Text('Cancel'), onPressed: () { Navigator.of(context).pop(); }, ), ], ), ); } Future showConfirmDialog( BuildContext context, String translationKey, ok(), {List translationVariables}) async { await showDialog( context: context, builder: (_) { return AlertDialog( title: Center( child: LocalText( context, translationKey, translationVariables: translationVariables, ), ), content: Container( child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ FlatButton( child: Text( AppTranslations.of(context).text('Cancel'), style: Provider.of(context).isEng ? TextStyle() : TextStyle(fontFamily: 'MyanmarUnicode'), ), onPressed: () { Navigator.of(context).pop(); }), FlatButton( color: primaryColor, child: Text(AppTranslations.of(context).text('Ok'), style: Provider.of(context).isEng ? TextStyle( color: Colors.white, fontWeight: FontWeight.bold) : TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontFamily: 'MyanmarUnicode')), onPressed: () async { Navigator.of(context).pop(); await ok(); }) ], ), ), ); }); } void showCommentDialog(BuildContext context, commentCallback(comment)) { TextEditingController _comment = new TextEditingController(); showDialog( context: context, builder: (_) { return AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(32.0))), content: Container( width: 300.0, height: 80.0, child: Container( child: TextFormField( controller: _comment, autofocus: false, cursorColor: primaryColor, maxLines: 3, style: textStyle, decoration: new InputDecoration( labelText: "Comment", labelStyle: labelStyle, icon: Icon( Icons.add_comment, color: primaryColor, ), enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: primaryColor, width: 1.0)), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: primaryColor, width: 1.0)), ), validator: (value) { if (value.isEmpty) { return "Please enter comment"; } return null; }, ), ), ), actions: [ FlatButton( child: Text( "Cancel", style: labelStyle, ), onPressed: () { _comment.clear(); Navigator.of(context).pop(); }), FlatButton( color: primaryColor, child: Text("Submit", style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold)), onPressed: () { commentCallback(_comment.text); Navigator.of(context).pop(); }) ], ); }); } Widget getStatus(String status) { return status == "Delivered" ? Chip( backgroundColor: Colors.green, avatar: Icon( Icons.check, color: Colors.white, size: 14, ), label: Text( status, style: TextStyle(color: Colors.white, fontSize: 12), )) : 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), )) : status == "In progress" ? Chip( backgroundColor: Colors.red, avatar: Icon( Icons.timelapse, color: Colors.white, size: 14, ), label: Text( status, style: TextStyle(color: Colors.white, fontSize: 12), )) : status == "Pickuped" ? Text( status, style: TextStyle( color: primaryColor, fontSize: 18, fontWeight: FontWeight.bold), ) : status == "Pending" || status == "Rescheduled" ? Row( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Icon(Icons.schedule), ), Text( status, style: TextStyle( color: primaryColor, fontSize: 18, fontWeight: FontWeight.bold), ) ], ) : status == "Assigned" ? Row( children: [ 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), ) : status == "Delivered" ? Text( status, style: TextStyle( color: Colors.green, fontSize: 12), ) : Chip( avatar: Icon( Icons.check, size: 14, ), label: Text(status)); } call(BuildContext context, String phone) { showConfirmDialog(context, "contact.phone.confim", () => launch("tel:$phone"), translationVariables: ["$phone"]); } Future displayNotiContent( BuildContext context, Noti.Notification noti) async { if (!noti.seen) { Provider.of(context, listen: false).seenID(noti.id); } try { if (noti.itemType == "buyer") { BuyerModel buyerModel = Provider.of(context, listen: false); Buyer buyer = await buyerModel.getBuyer(noti.itemID); Navigator.push( context, MaterialPageRoute( builder: (context) => BuyerInfo( buyer: buyer, )), ); } else if (noti.itemType == "announcement") { AnnouncementModel announcementModel = Provider.of(context, listen: false); var announce = await announcementModel.getAnnouncement(noti.itemID); Navigator.push( context, MaterialPageRoute( builder: (context) => AnnouncementPage(announcement: announce)), ); } else if (noti.itemType == "reg") { Navigator.push( context, MaterialPageRoute(builder: (context) => MyRegisterationInfo()), ); } else if (noti.itemType == "po") { POSubmissionModel poModel = Provider.of(context, listen: false); var po = await poModel.getPO(noti.itemID); Navigator.push( context, MaterialPageRoute( builder: (context) => POSubmissionForm( poSubmission: po, )), ); } else if (noti.itemType == "do") { DOModel doModel = Provider.of(context, listen: false); var _do = await doModel.getDO(noti.itemID); Navigator.push( context, MaterialPageRoute(builder: (context) => DOApproval(doSubmission: _do)), ); } else if (noti.itemType == "price") { Navigator.of(context) .push(MaterialPageRoute(builder: (_) => ProductsList())); } else if (noti.itemType == 'new_device_login') { Navigator.of(context).push(MaterialPageRoute(builder: (_) => LogList())); } else if (noti.itemType == 'user') { UserModel userModel = Provider.of(context, listen: false); var user = await userModel.getUser(noti.itemID); Navigator.of(context).push(MaterialPageRoute( builder: (_) => UserEditor( user: user, viewOnly: true, ))); } } catch (e) { log.warning("Error:$e \n ${noti.toString()}"); showMsgDialog(context, "Error", "Notification item not found!"); } finally {} } Widget nameWidget(String name) { return Center( child: Padding( padding: const EdgeInsets.only(left: 10.0, top: 8), child: Text( name, style: TextStyle( color: Colors.black87, fontSize: 18, fontWeight: FontWeight.bold), ), ), ); } Widget phoneWidget(BuildContext context, String phone) { return Container( padding: EdgeInsets.only(top: 10), child: Row( children: [ Icon(Icons.phone), Padding( padding: const EdgeInsets.only(right: 8.0), child: labeledText(context, phone, "user.phone"), ), ], ), ); } Widget fcsInput(String label, IconData iconData, {TextEditingController controller,String value}) { return Row( children: [ Padding( padding: const EdgeInsets.only(right: 8.0), child: Icon(iconData), ), Expanded( child: Container( height: 50.0, child: Row(children: [ Expanded( child: TextFormField( initialValue: value, controller: controller, cursorColor: primaryColor, textAlign: TextAlign.left, decoration: new InputDecoration( contentPadding: EdgeInsets.only(top: 8), labelText: label, enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: primaryColor, width: 1.0)), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: primaryColor, width: 1.0)), ), )), ]), )), ], ); } Widget fcsDropDown(String label, IconData iconData, {TextEditingController controller}) { return Row( children: [ Padding( padding: const EdgeInsets.only(right: 8.0), child: Icon(iconData), ), Expanded( child: Container( height: 50.0, child: Row(children: [ Expanded(child: _dropDown()), ]), )), ], ); } Widget _dropDown() { return DropdownButton( value: "Ko Nge", icon: Icon(Icons.arrow_downward), iconSize: 24, elevation: 16, // style: TextStyle(color: Colors.deepPurple), underline: Container( height: 2, color: primaryColor, ), onChanged: (String newValue) {}, items: ['Ko Nge', 'Two', 'Free', 'Four'] .map>((String value) { return DropdownMenuItem( value: value, child: Text(value), ); }).toList(), ); } Widget fcsButton(BuildContext context, String text,{Function callack}) { return Container( padding: EdgeInsets.only(left: 10, right: 10, top: 10), child: Container( height: 45.0, decoration: BoxDecoration( color: primaryColor, shape: BoxShape.rectangle, ), child: ButtonTheme( minWidth: 900.0, height: 100.0, child: FlatButton( onPressed: callack, child: Text(text, style: TextStyle( color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold, )), ), ), ), ); }