diff --git a/lib/domain/entities/setting.dart b/lib/domain/entities/setting.dart index dd85745..b9d303c 100644 --- a/lib/domain/entities/setting.dart +++ b/lib/domain/entities/setting.dart @@ -54,20 +54,13 @@ class Setting { emailAddress: map['email_address'], facebookLink: map['facebook_link'], about: map['about'], - termsEng: map['terms_eng'], - termsMm: map['terms_mm'], + termsEng: map['terms_eng_markdown'], + termsMm: map['terms_mm_markdown'], shipmentTypes: List.from(map['shipment_types']), courierWebsite: map['courier_website'], ); } - Map toMap() { - return { - 'terms_eng': termsEng, - 'terms_mm': termsMm, - }; - } - @override String toString() { return 'Setting{supportBuildNum:$supportBuildNum,about:$about}'; diff --git a/lib/helpers/pdf.dart b/lib/helpers/pdf.dart index 33ae573..a80784c 100644 --- a/lib/helpers/pdf.dart +++ b/lib/helpers/pdf.dart @@ -38,7 +38,7 @@ Future generateCartonPdf(Carton carton) async { height: 50, color: PdfColor.fromHex("#000000"), barcode: pw.Barcode.qrCode(), - data: carton.cartonNumber!), + data: carton.cartonNumber ?? ""), pw.Padding( padding: const pw.EdgeInsets.all(5), child: pw.Column( diff --git a/lib/pages/carton/print_qr_code_page.dart b/lib/pages/carton/print_qr_code_page.dart index cdd8d3f..e3634f6 100644 --- a/lib/pages/carton/print_qr_code_page.dart +++ b/lib/pages/carton/print_qr_code_page.dart @@ -26,21 +26,24 @@ class PrintQrCodePage extends StatelessWidget { Row( children: [ QrImageView( - data: 'This is a simple QR code', - version: QrVersions.auto, - size: 100, - gapless: true, - ), + data: carton.cartonNumber ?? "", + version: QrVersions.auto, + size: 100, + gapless: true), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(carton.cartonNumber ?? "", - style: TextStyle(fontSize: 18,fontFamily: "Roboto")), - Text(carton.userName!, style: TextStyle(fontSize: 16,fontFamily: "Roboto")), + style: TextStyle(fontSize: 18, fontFamily: "Roboto")), + Text(carton.userName!, + style: TextStyle(fontSize: 16, fontFamily: "Roboto")), Padding( padding: const EdgeInsets.only(top: 3), child: Text("${carton.actualWeight} lb", - style: TextStyle(fontSize: 16, color: labelColor,fontFamily: "Roboto")), + style: TextStyle( + fontSize: 16, + color: labelColor, + fontFamily: "Roboto")), ) ], ) @@ -54,7 +57,7 @@ class PrintQrCodePage extends StatelessWidget { color: primaryColor, iconData: Icons.print_outlined, callBack: () { - generateCartonPdf(carton); + generateCartonPdf(carton); }, ), ) diff --git a/lib/pages/carton/widget/carton_list_row.dart b/lib/pages/carton/widget/carton_list_row.dart index 6a4641d..08df328 100644 --- a/lib/pages/carton/widget/carton_list_row.dart +++ b/lib/pages/carton/widget/carton_list_row.dart @@ -33,7 +33,7 @@ class CartonListRow extends StatelessWidget { child: new Row( children: [ Container( - padding: EdgeInsets.only(left: 5), + padding: EdgeInsets.only(left: 0), child: Icon( MaterialCommunityIcons.package, color: primaryColor, @@ -42,7 +42,7 @@ class CartonListRow extends StatelessWidget { ), new Expanded( child: Padding( - padding: const EdgeInsets.only(left: 18.0), + padding: const EdgeInsets.only(left: 15.0), child: Row( children: [ new Column( @@ -98,7 +98,7 @@ class CartonListRow extends StatelessWidget { new Text( "${box.cartonWeight.toStringAsFixed(2)} lb", style: - new TextStyle(fontSize: 15.0, color: Colors.grey), + new TextStyle(fontSize: 14.0, color: Colors.grey), ), ], ), diff --git a/lib/pages/customer/invitation_create.dart b/lib/pages/customer/invitation_create.dart index a148e81..f937e7c 100644 --- a/lib/pages/customer/invitation_create.dart +++ b/lib/pages/customer/invitation_create.dart @@ -19,6 +19,7 @@ class _InvitationCreateState extends State { bool _isLoading = false; late String dialCode; + final _inviteFormKey = GlobalKey(); @override void initState() { @@ -34,9 +35,17 @@ class _InvitationCreateState extends State { @override Widget build(BuildContext context) { final nameBox = InputText( - labelTextKey: 'customer.name', - iconData: Icons.person, - controller: _nameController); + labelTextKey: 'customer.name', + iconData: Icons.person, + controller: _nameController, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (value) { + if (value == null || value.isEmpty) { + return "Please insert name"; + } + return null; + }, + ); return LocalProgress( inAsyncCall: _isLoading, @@ -56,73 +65,88 @@ class _InvitationCreateState extends State { } }, ), - body: Container( - padding: EdgeInsets.all(18), - child: ListView( - children: [ - nameBox, - SizedBox(height: 10), - Row( - children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Icon( - Icons.phone, - color: primaryColor, + body: Form( + key: _inviteFormKey, + child: Container( + padding: EdgeInsets.all(18), + child: ListView( + children: [ + nameBox, + SizedBox(height: 10), + Row( + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: Icon( + Icons.phone, + color: primaryColor, + ), ), - ), - Container( - decoration: BoxDecoration( - border: - Border.all(color: Colors.grey.shade400, width: 1), - borderRadius: BorderRadius.all(Radius.circular(12.0))), - child: CountryCodePicker( - onChanged: _countryChange, - initialSelection: dialCode, - countryFilter: ['mm', 'us'], - showCountryOnly: false, - showOnlyCountryWhenClosed: false, - alignLeft: false, - textStyle: TextStyle(fontSize: 16, color: Colors.black87), - searchDecoration: InputDecoration( - focusedBorder: UnderlineInputBorder( - borderSide: - BorderSide(color: Colors.black, width: 1.0))), + Container( + decoration: BoxDecoration( + border: + Border.all(color: Colors.grey.shade400, width: 1), + borderRadius: + BorderRadius.all(Radius.circular(12.0))), + child: CountryCodePicker( + onChanged: _countryChange, + initialSelection: dialCode, + countryFilter: ['mm', 'us'], + showCountryOnly: false, + showOnlyCountryWhenClosed: false, + alignLeft: false, + textStyle: + TextStyle(fontSize: 16, color: Colors.black87), + searchDecoration: InputDecoration( + focusedBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: Colors.black, width: 1.0))), + ), ), - ), - SizedBox( - width: 10, - ), - Flexible( - child: Container( - padding: EdgeInsets.only(top: 10, bottom: 10), - child: TextFormField( - controller: _phoneController, - cursorColor: primaryColor, - textAlign: TextAlign.left, - keyboardType: TextInputType.phone, - style: TextStyle( - fontSize: 18, - ), - decoration: InputDecoration( - fillColor: Colors.white, - labelText: getLocalString(context, "customer.phone"), - labelStyle: - TextStyle(fontSize: 16, color: Colors.grey), - filled: true, - focusedBorder: UnderlineInputBorder( - borderSide: - BorderSide(color: Colors.grey, width: 1.0)), + SizedBox( + width: 10, + ), + Flexible( + child: Container( + padding: EdgeInsets.only(top: 10, bottom: 10), + child: TextFormField( + controller: _phoneController, + cursorColor: primaryColor, + textAlign: TextAlign.left, + keyboardType: TextInputType.phone, + style: TextStyle( + fontSize: 18, + ), + decoration: InputDecoration( + fillColor: Colors.white, + labelText: + getLocalString(context, "customer.phone"), + labelStyle: + TextStyle(fontSize: 16, color: Colors.grey), + filled: true, + focusedBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: Colors.grey, width: 1.0)), + errorStyle: TextStyle( + color: dangerColor, + )), + validator: (value) { + if (value == null || value.isEmpty) { + return "Please insert phone no"; + } + return null; + }, + autovalidateMode: AutovalidateMode.onUserInteraction, ), ), ), - ), - ], - ), - SizedBox(height: 20), - fcsButton(context, getLocalString(context, "invite.btn"), - callack: _invite), - ], + ], + ), + SizedBox(height: 20), + fcsButton(context, getLocalString(context, "invite.btn"), + callack: _invite), + ], + ), ), ), ), @@ -138,9 +162,9 @@ class _InvitationCreateState extends State { _invite() async { String userName = _nameController.text; String phoneNumber = dialCode + _phoneController.text; - if (userName == "" || phoneNumber == "") { - showMsgDialog(context, "Error", "Invalid name or phone number"); - return; + + if (!_inviteFormKey.currentState!.validate()) { + return null; } setState(() { _isLoading = true; diff --git a/lib/pages/delivery/delivery_list_row.dart b/lib/pages/delivery/delivery_list_row.dart index c77f115..6466003 100644 --- a/lib/pages/delivery/delivery_list_row.dart +++ b/lib/pages/delivery/delivery_list_row.dart @@ -1,6 +1,5 @@ import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; @@ -9,8 +8,8 @@ import 'package:intl/intl.dart'; import 'delivery_info.dart'; class DeliveryListRow extends StatelessWidget { - final Carton? box; - DeliveryListRow({Key? key, this.box}) : super(key: key); + final Carton box; + DeliveryListRow({Key? key, required this.box}) : super(key: key); final double dotSize = 15.0; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); @@ -19,11 +18,10 @@ class DeliveryListRow extends StatelessWidget { Widget build(BuildContext context) { return InkWell( onTap: () { - if (box != null) - Navigator.push( - context, - CupertinoPageRoute(builder: (context) => DeliveryInfo(box: box!)), - ); + Navigator.push( + context, + CupertinoPageRoute(builder: (context) => DeliveryInfo(box: box)), + ); }, child: Container( padding: EdgeInsets.only(left: 15, right: 15), @@ -31,38 +29,32 @@ class DeliveryListRow extends StatelessWidget { children: [ Expanded( child: new Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0), + padding: const EdgeInsets.symmetric(vertical: 13.0), child: new Row( children: [ - Container( - padding: EdgeInsets.only(left: 5, right: 10), - child: Icon( - MaterialCommunityIcons.truck_fast, - color: primaryColor, - size: 30, - ), - ), + Icon(MaterialCommunityIcons.truck_fast, + color: primaryColor, size: 30), new Expanded( - child: new Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - box?.cartonNumber ?? "", + child: Padding( + padding: const EdgeInsets.only(left: 15), + child: new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Text( + box.cartonNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), - ), - Padding( - padding: const EdgeInsets.only(left: 10.0, top: 10), - child: new Text( - box?.userName ?? "", - style: new TextStyle( - fontSize: 15.0, color: Colors.grey), - ), - ) - ], + Padding( + padding: const EdgeInsets.only(top: 5), + child: new Text( + box.userName ?? "", + style: new TextStyle( + fontSize: 15.0, color: Colors.grey), + ), + ) + ], + ), ), ), ], @@ -70,19 +62,21 @@ class DeliveryListRow extends StatelessWidget { ), ), Column( + crossAxisAlignment: CrossAxisAlignment.end, children: [ + Text(box.status ?? "", + style: TextStyle( + color: primaryColor, + fontSize: 15, + fontWeight: FontWeight.bold)), Padding( - padding: const EdgeInsets.all(0), - child: getStatus(box?.status ?? ''), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5), + padding: const EdgeInsets.only(top: 5), child: Row( children: [ new Text( - "${box?.actualWeight.toString() ?? ''} lb", + "${box.actualWeight.toString()} lb", style: - new TextStyle(fontSize: 15.0, color: Colors.grey), + new TextStyle(fontSize: 14.0, color: Colors.grey), ), ], ), diff --git a/lib/pages/discount/discount_list_row.dart b/lib/pages/discount/discount_list_row.dart index 405c9a4..53268b9 100644 --- a/lib/pages/discount/discount_list_row.dart +++ b/lib/pages/discount/discount_list_row.dart @@ -8,8 +8,9 @@ typedef OnSelect(Discount discount); class DiscountListRow extends StatelessWidget { final OnSelect? onSelect; - final Discount? discount; - DiscountListRow({Key? key, this.discount, this.onSelect}) : super(key: key); + final Discount discount; + DiscountListRow({Key? key, required this.discount, this.onSelect}) + : super(key: key); final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); @@ -17,9 +18,7 @@ class DiscountListRow extends StatelessWidget { Widget build(BuildContext context) { return InkWell( onTap: () { - if (onSelect != null && discount != null) { - onSelect!(discount!); - } + onSelect!(discount); }, child: Container( padding: EdgeInsets.only(left: 15, right: 15), @@ -27,38 +26,31 @@ class DiscountListRow extends StatelessWidget { children: [ Expanded( child: new Padding( - padding: const EdgeInsets.symmetric(vertical: 16.0), + padding: const EdgeInsets.symmetric(vertical: 13), child: new Row( children: [ - Container( - padding: EdgeInsets.only(left: 5, right: 10), - child: Icon( - Entypo.price_ribbon, - color: primaryColor, - size: 30, - ), - ), + Icon(Entypo.price_ribbon, color: primaryColor, size: 30), new Expanded( - child: new Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - discount?.code ?? "", + child: Padding( + padding: const EdgeInsets.only(left: 15), + child: new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Text( + discount.code ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), - ), - Padding( - padding: const EdgeInsets.only(left: 10.0, top: 10), - child: new Text( - discount?.customerName ?? "", - style: new TextStyle( - fontSize: 15.0, color: Colors.grey), - ), - ) - ], + Padding( + padding: const EdgeInsets.only(top: 5), + child: new Text( + discount.customerName ?? "", + style: new TextStyle( + fontSize: 15.0, color: Colors.grey), + ), + ) + ], + ), ), ), ], @@ -66,17 +58,17 @@ class DiscountListRow extends StatelessWidget { ), ), Column( + crossAxisAlignment: CrossAxisAlignment.end, children: [ + Text(discount.status ?? ''), Padding( - padding: const EdgeInsets.all(0), - child: Text(discount?.status ?? ''), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5), + padding: const EdgeInsets.only( + top: 5, + ), child: Row( children: [ new Text( - "${discount?.amount.toStringAsFixed(2) ?? ''}", + "${discount.amount.toStringAsFixed(2)}", style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index a5f3448..92985e8 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -121,6 +121,7 @@ class _FcsShipmentEditorState extends State { labelTextKey: "FCSshipment.number", iconData: Ionicons.ios_airplane, controller: _shipmentNumberController, + autovalidateMode: AutovalidateMode.onUserInteraction, validator: (value) { if (value!.isEmpty) { return "Enter shipment number"; @@ -132,6 +133,7 @@ class _FcsShipmentEditorState extends State { labelTextKey: "FCSshipment.cutoff_date", iconData: Icons.date_range, controller: _cutoffDateController, + autovalidateMode: AutovalidateMode.onUserInteraction, validator: (value) { if (value!.isEmpty) { return "Select cutoff date"; @@ -143,6 +145,7 @@ class _FcsShipmentEditorState extends State { labelTextKey: "FCSshipment.ETA", iconData: Icons.date_range, controller: _arrivalDateController, + autovalidateMode: AutovalidateMode.onUserInteraction, validator: (value) { if (value!.isEmpty) { return "Select ETA date"; diff --git a/lib/pages/fcs_shipment/fcs_shipment_list_row.dart b/lib/pages/fcs_shipment/fcs_shipment_list_row.dart index 59a7837..50ff32f 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_list_row.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_list_row.dart @@ -24,20 +24,17 @@ class FcsShipmentListRow extends StatelessWidget { children: [ Expanded( child: new Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0), + padding: const EdgeInsets.symmetric(vertical: 13), child: new Row( children: [ - Container( - padding: EdgeInsets.only(left: 5), - child: Icon( - Ionicons.ios_airplane, - color: primaryColor, - size: 30, - ), + Icon( + Ionicons.ios_airplane, + color: primaryColor, + size: 30, ), new Expanded( child: Padding( - padding: const EdgeInsets.only(left: 18.0), + padding: const EdgeInsets.only(left: 15), child: new Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/pages/package/package_list_row.dart b/lib/pages/package/package_list_row.dart index a613c26..aa05379 100644 --- a/lib/pages/package/package_list_row.dart +++ b/lib/pages/package/package_list_row.dart @@ -1,6 +1,5 @@ import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/package_info.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -11,14 +10,14 @@ typedef CallbackPackageSelect(Package package); class PackageListRow extends StatelessWidget { final bool isCustomer; - final Package? package; + final Package package; final CallbackPackageSelect? callbackPackageSelect; final double dotSize = 15.0; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); PackageListRow( {Key? key, - this.package, + required this.package, this.callbackPackageSelect, this.isCustomer = false}) : super(key: key); @@ -28,7 +27,7 @@ class PackageListRow extends StatelessWidget { return InkWell( onTap: () { if (callbackPackageSelect != null) { - callbackPackageSelect!(package!); + callbackPackageSelect!(package); return; } Navigator.push( @@ -48,36 +47,33 @@ class PackageListRow extends StatelessWidget { children: [ Expanded( child: new Padding( - padding: const EdgeInsets.symmetric(vertical: 16.0), + padding: const EdgeInsets.symmetric(vertical: 13), child: new Row( children: [ Icon(Octicons.package, color: primaryColor), - SizedBox(width: 8), new Expanded( - child: new Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - package!.id == null - ? '' - : package!.trackingID!, + child: Padding( + padding: const EdgeInsets.only(left: 15), + child: new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Text( + package.id == null ? '' : package.trackingID!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - package!.market == null - ? '' - : package!.market!, - style: new TextStyle( - fontSize: 15.0, color: Colors.black), + Padding( + padding: const EdgeInsets.only(top: 5), + child: new Text( + package.market == null + ? '' + : package.market!, + style: new TextStyle( + fontSize: 15.0, color: Colors.black), + ), ), - ), - ], + ], + ), ), ), ], @@ -85,19 +81,21 @@ class PackageListRow extends StatelessWidget { ), ), Column( + crossAxisAlignment: CrossAxisAlignment.end, children: [ + Text(package.status ?? "", + style: TextStyle( + color: primaryColor, + fontSize: 15, + fontWeight: FontWeight.bold)), Padding( - padding: const EdgeInsets.all(3.0), - child: getStatus(package!.status??""), - ), - Padding( - padding: const EdgeInsets.all(0), + padding: const EdgeInsets.only(top: 5), child: new Text( - package!.currentStatusDate != null - ? dateFormat.format(package!.currentStatusDate!) + package.currentStatusDate != null + ? dateFormat.format(package.currentStatusDate!) : '', style: - new TextStyle(fontSize: 15.0, color: Colors.grey), + new TextStyle(fontSize: 14.0, color: Colors.grey), ), ), ], diff --git a/lib/pages/pickup/pickup_list.dart b/lib/pages/pickup/pickup_list.dart index 97361dd..2d4215c 100644 --- a/lib/pages/pickup/pickup_list.dart +++ b/lib/pages/pickup/pickup_list.dart @@ -2,7 +2,7 @@ import 'package:fcs/domain/entities/pickup.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/pickup/pickup_info.dart'; import 'package:fcs/pages/pickup/pickup_list_row.dart'; -import 'package:fcs/pages/pickup_search/pickup_serach.dart'; +import 'package:fcs/pages/pickup_search/pickup_search.dart'; import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:fcs/pagination/paginator_listview.dart'; diff --git a/lib/pages/pickup/pickup_list_row.dart b/lib/pages/pickup/pickup_list_row.dart index b66a824..862bb5f 100644 --- a/lib/pages/pickup/pickup_list_row.dart +++ b/lib/pages/pickup/pickup_list_row.dart @@ -1,6 +1,5 @@ import 'package:fcs/domain/entities/pickup.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/pickup/pickup_info.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -37,51 +36,53 @@ class PickupListRow extends StatelessWidget { children: [ Expanded( child: new Padding( - padding: const EdgeInsets.symmetric(vertical: 16.0), + padding: const EdgeInsets.symmetric(vertical: 13), child: new Row( children: [ - Container( - padding: EdgeInsets.only(left: 5, right: 10), - child: Icon( - SimpleLineIcons.direction, - color: primaryColor, - size: 30, - ), + Icon( + SimpleLineIcons.direction, + color: primaryColor, + size: 30, ), new Expanded( - child: new Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( + child: Padding( + padding: const EdgeInsets.only(left: 15.0), + child: new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Text( pickup?.pickupNumber ?? '', style: new TextStyle( fontSize: 15.0, color: Colors.black), ), - ), - Padding( - padding: const EdgeInsets.only(left: 10.0, top: 10), - child: new Text( - pickup!.pickupDate != null - ? dateFormat.format(pickup!.pickupDate!) - : "", - style: new TextStyle( - fontSize: 15.0, color: Colors.grey), - ), - ) - ], + Padding( + padding: const EdgeInsets.only(top: 5), + child: new Text( + pickup!.pickupDate != null + ? dateFormat.format(pickup!.pickupDate!) + : "", + style: new TextStyle( + fontSize: 15.0, color: Colors.grey), + ), + ) + ], + ), ), ), ], ), ), ), - Column( - children: [ - getStatus(pickup!.status ?? ""), - ], - ) + Text(pickup?.status ?? "", + style: TextStyle( + color: primaryColor, + fontSize: 15, + fontWeight: FontWeight.bold)), + // Column( + // children: [ + // getStatus(pickup!.status ?? ""), + // ], + // ) ], ), ), diff --git a/lib/pages/pickup_search/pickup_serach.dart b/lib/pages/pickup_search/pickup_search.dart similarity index 100% rename from lib/pages/pickup_search/pickup_serach.dart rename to lib/pages/pickup_search/pickup_search.dart diff --git a/lib/pages/processing/processing_list_row.dart b/lib/pages/processing/processing_list_row.dart index d702d4f..e308227 100644 --- a/lib/pages/processing/processing_list_row.dart +++ b/lib/pages/processing/processing_list_row.dart @@ -1,6 +1,5 @@ import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; @@ -11,12 +10,13 @@ import 'processing_info.dart'; typedef CallbackPackageSelect(Package package); class ProcessingListRow extends StatelessWidget { - final Package? package; + final Package package; final CallbackPackageSelect? callbackPackageSelect; final double dotSize = 15.0; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); - ProcessingListRow({Key? key, this.package, this.callbackPackageSelect}) + ProcessingListRow( + {Key? key, required this.package, this.callbackPackageSelect}) : super(key: key); @override @@ -24,7 +24,7 @@ class ProcessingListRow extends StatelessWidget { return InkWell( onTap: () { if (callbackPackageSelect != null) { - callbackPackageSelect!(package!); + callbackPackageSelect!(package); return; } Navigator.push( @@ -39,38 +39,33 @@ class ProcessingListRow extends StatelessWidget { children: [ Expanded( child: new Padding( - padding: const EdgeInsets.symmetric(vertical: 16.0), + padding: const EdgeInsets.symmetric(vertical: 13.0), child: new Row( children: [ - Container( - padding: EdgeInsets.only(left: 5, right: 10), - child: Icon( - FontAwesome.dropbox, - color: primaryColor, - size: 30, - ), - ), + Icon(FontAwesome.dropbox, color: primaryColor, size: 30), new Expanded( - child: new Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - package!.id == null ? '' : package!.trackingID!, + child: Padding( + padding: const EdgeInsets.only(left: 15), + child: new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Text( + package.trackingID == null + ? '' + : package.trackingID!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - package!.market == null ? '' : package!.market!, - style: new TextStyle( - fontSize: 15.0, color: Colors.black), + Padding( + padding: const EdgeInsets.only(top: 5.0), + child: new Text( + package.market == null ? '' : package.market!, + style: new TextStyle( + fontSize: 15.0, color: Colors.black), + ), ), - ), - ], + ], + ), ), ), ], @@ -78,18 +73,20 @@ class ProcessingListRow extends StatelessWidget { ), ), Column( + crossAxisAlignment: CrossAxisAlignment.end, children: [ + Text(package.status ?? "", + style: TextStyle( + color: primaryColor, + fontSize: 15, + fontWeight: FontWeight.bold)), Padding( - padding: const EdgeInsets.all(3.0), - child: getStatus(package!.status??""), - ), - Padding( - padding: const EdgeInsets.all(0), + padding: const EdgeInsets.only(top: 5), child: new Text( - package!.currentStatusDate != null - ? dateFormat.format(package!.currentStatusDate!) + package.currentStatusDate != null + ? dateFormat.format(package.currentStatusDate!) : '', - style: new TextStyle(fontSize: 15.0, color: Colors.grey), + style: new TextStyle(fontSize: 14.0, color: Colors.grey), ), ), ], diff --git a/lib/pages/rates/cargo_editor.dart b/lib/pages/rates/cargo_editor.dart index e9db900..51a5407 100644 --- a/lib/pages/rates/cargo_editor.dart +++ b/lib/pages/rates/cargo_editor.dart @@ -24,6 +24,7 @@ class _CargoEditorState extends State { bool _isLoading = false; late CargoType _cargo; bool _isNew = false; + final _cargoFormKey = GlobalKey(); @override void initState() { @@ -47,11 +48,26 @@ class _CargoEditorState extends State { final typeBox = InputText( labelTextKey: 'cargo.type', iconData: Icons.text_format, - controller: _descController); + controller: _descController, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (value){ + if(value==null || value.isEmpty){ + return "Please insert cargo type"; + } + return null; + },); final rateBox = InputText( - labelTextKey: 'cargo.rate', - iconData: Icons.attach_money, - controller: _rateController); + labelTextKey: 'cargo.rate', + iconData: Icons.attach_money, + controller: _rateController, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (value) { + if (value == null || value.isEmpty) { + return "Please insert rate"; + } + return null; + }, + ); return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( @@ -78,23 +94,26 @@ class _CargoEditorState extends State { ) ], ), - body: Container( - padding: EdgeInsets.all(18), - child: Column( - children: [ - Expanded( - child: ListView( - children: [ - typeBox, - rateBox, - SizedBox(height: 30), - ], + body: Form( + key: _cargoFormKey, + child: Container( + padding: EdgeInsets.all(18), + child: Column( + children: [ + Expanded( + child: ListView( + children: [ + typeBox, + rateBox, + SizedBox(height: 30), + ], + ), ), - ), - fcsButton(context, getLocalString(context, "btn.save"), - callack: _save), - SizedBox(height: 10) - ], + fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), + SizedBox(height: 10) + ], + ), ), ), ), @@ -102,8 +121,7 @@ class _CargoEditorState extends State { } _save() async { - if (_rateController.text == "") { - showMsgDialog(context, "Error", "Please insert rate"); + if (!_cargoFormKey.currentState!.validate()) { return; } setState(() { diff --git a/lib/pages/rates/custom_editor.dart b/lib/pages/rates/custom_editor.dart index cde6be0..43d4dad 100644 --- a/lib/pages/rates/custom_editor.dart +++ b/lib/pages/rates/custom_editor.dart @@ -26,6 +26,7 @@ class _CustomEditorState extends State { bool _isLoading = false; CargoType _custom = new CargoType(); bool _isNew = false; + final _customFormKey = GlobalKey(); @override void initState() { @@ -50,16 +51,39 @@ class _CustomEditorState extends State { final productBox = InputText( labelTextKey: 'rate.cutom.product_type', iconData: FontAwesomeIcons.weightHanging, - controller: _productController); + autovalidateMode: AutovalidateMode.onUserInteraction, + controller: _productController, + validator: (value){ + if(value==null || value.isEmpty){ + return "Please insert product type"; + } + return null; + },); final feeBox = InputText( - labelTextKey: 'rate.custom.fee', - iconData: Icons.attach_money, - controller: _feeController); + labelTextKey: 'rate.custom.fee', + iconData: Icons.attach_money, + controller: _feeController, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (value) { + if (value == null || value.isEmpty) { + return "Please insert fee"; + } + return null; + }, + ); final shipmentRateBox = InputText( - labelTextKey: 'rate.custom.shipment_rate', - iconData: Icons.attach_money, - controller: _shipmentRateController); + labelTextKey: 'rate.custom.shipment_rate', + iconData: Icons.attach_money, + controller: _shipmentRateController, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (value) { + if (value == null || value.isEmpty) { + return "Please insert shipment rate"; + } + return null; + }, + ); return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( @@ -86,24 +110,27 @@ class _CustomEditorState extends State { ) ], ), - body: Container( - padding: EdgeInsets.all(18), - child: Column( - children: [ - Expanded( - child: ListView( - children: [ - productBox, - feeBox, - shipmentRateBox, - SizedBox(height: 30), - ], + body: Form( + key: _customFormKey, + child: Container( + padding: EdgeInsets.all(18), + child: Column( + children: [ + Expanded( + child: ListView( + children: [ + productBox, + feeBox, + shipmentRateBox, + SizedBox(height: 30), + ], + ), ), - ), - fcsButton(context, getLocalString(context, "btn.save"), - callack: _save), - SizedBox(height: 10) - ], + fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), + SizedBox(height: 10) + ], + ), ), ), ), @@ -111,13 +138,7 @@ class _CustomEditorState extends State { } _save() async { - if (_feeController.text == "") { - showMsgDialog(context, "Error", "Please insert fee"); - return; - } - - if (_shipmentRateController.text == "") { - showMsgDialog(context, "Error", "Please insert shipment rate"); + if (!_customFormKey.currentState!.validate()) { return; } diff --git a/lib/pages/rates/discount_by_weight_editor.dart b/lib/pages/rates/discount_by_weight_editor.dart index 53791a8..5a6308f 100644 --- a/lib/pages/rates/discount_by_weight_editor.dart +++ b/lib/pages/rates/discount_by_weight_editor.dart @@ -24,6 +24,7 @@ class _DiscountByWeightEditorState extends State { bool _isLoading = false; bool _isNew = false; DiscountByWeight _discountByWeight = new DiscountByWeight(); + final _discountFormKey = GlobalKey(); @override void initState() { @@ -46,13 +47,29 @@ class _DiscountByWeightEditorState extends State { @override Widget build(BuildContext context) { final weightBox = InputText( - labelTextKey: 'rate.discount.weight', - iconData: FontAwesomeIcons.weightHanging, - controller: _weightController); + labelTextKey: 'rate.discount.weight', + iconData: FontAwesomeIcons.weightHanging, + controller: _weightController, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (value) { + if (value == null || value.isEmpty) { + return "Please inset weight"; + } + return null; + }, + ); final discountRateBox = InputText( - labelTextKey: 'rate.discount.rate', - iconData: Icons.attach_money, - controller: _discountController); + labelTextKey: 'rate.discount.rate', + iconData: Icons.attach_money, + controller: _discountController, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (value) { + if (value == null || value.isEmpty) { + return "Please insert discount rate"; + } + return null; + }, + ); return LocalProgress( inAsyncCall: _isLoading, @@ -80,23 +97,26 @@ class _DiscountByWeightEditorState extends State { ) ], ), - body: Container( - padding: EdgeInsets.all(18), - child: Column( - children: [ - Expanded( - child: ListView( - children: [ - weightBox, - discountRateBox, - SizedBox(height: 30), - ], + body: Form( + key: _discountFormKey, + child: Container( + padding: EdgeInsets.all(18), + child: Column( + children: [ + Expanded( + child: ListView( + children: [ + weightBox, + discountRateBox, + SizedBox(height: 30), + ], + ), ), - ), - fcsButton(context, getLocalString(context, "btn.save"), - callack: _save), - SizedBox(height: 10) - ], + fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), + SizedBox(height: 10) + ], + ), ), ), ), @@ -104,13 +124,7 @@ class _DiscountByWeightEditorState extends State { } _save() async { - if (_weightController.text == "") { - showMsgDialog(context, "Error", "Please insert weight"); - return; - } - - if (_discountController.text == "") { - showMsgDialog(context, "Error", "Please insert discount rate"); + if (!_discountFormKey.currentState!.validate()) { return; } diff --git a/lib/pages/receiving/receiving_editor.dart b/lib/pages/receiving/receiving_editor.dart index 2529530..78e9b92 100644 --- a/lib/pages/receiving/receiving_editor.dart +++ b/lib/pages/receiving/receiving_editor.dart @@ -30,6 +30,7 @@ class _ReceivingEditorState extends State { bool _isLoading = false; late bool _isNew; User? user; + final _receiveFormKey=GlobalKey(); TextEditingController _trackingIDCtl = new TextEditingController(); TextEditingController _remarkCtl = new TextEditingController(); MultiImgController _multiImgController = MultiImgController(); @@ -93,6 +94,14 @@ class _ReceivingEditorState extends State { iconData: MaterialCommunityIcons.barcode_scan, labelTextKey: "receiving.tracking.id", controller: _trackingIDCtl, + autovalidateMode: AutovalidateMode.onUserInteraction, + validator: (value){ + if(value==null || value.isEmpty){ + return "invalid tracking ID"; + } + return null; + }, + )), InkWell( onTap: _scan, @@ -159,29 +168,32 @@ class _ReceivingEditorState extends State { ), body: Padding( padding: const EdgeInsets.only(left: 12.0, right: 12), - child: ListView( - children: [ - trackingIDBox, - SizedBox( - height: 10, - ), - remarkBox, - Divider(), - img, - Divider(), - SizedBox( - height: 10, - ), - fcsIDBox, - namebox, - SizedBox( - height: 20, - ), - _isNew ? createButton : updateButton, - SizedBox( - height: 10, - ), - ], + child: Form( + key: _receiveFormKey, + child: ListView( + children: [ + trackingIDBox, + SizedBox( + height: 10, + ), + remarkBox, + Divider(), + img, + Divider(), + SizedBox( + height: 10, + ), + fcsIDBox, + namebox, + SizedBox( + height: 20, + ), + _isNew ? createButton : updateButton, + SizedBox( + height: 10, + ), + ], + ), ), ), )); @@ -216,8 +228,11 @@ class _ReceivingEditorState extends State { Package _p = Package(trackingID: _trackingIDCtl.text, remark: _remarkCtl.text); - if (_p.trackingID == null || _p.trackingID == "") { - showMsgDialog(context, "Error", "Invalid tracking ID!"); + // if (_p.trackingID == null || _p.trackingID == "") { + // showMsgDialog(context, "Error", "Invalid tracking ID!"); + // return; + // } + if (!_receiveFormKey.currentState!.validate()) { return; } diff --git a/lib/pages/receiving/receiving_list_row.dart b/lib/pages/receiving/receiving_list_row.dart index 95430de..c863c33 100644 --- a/lib/pages/receiving/receiving_list_row.dart +++ b/lib/pages/receiving/receiving_list_row.dart @@ -1,6 +1,5 @@ import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; @@ -11,12 +10,13 @@ import 'receiving_info.dart'; typedef CallbackPackageSelect(Package package); class ReceivingListRow extends StatelessWidget { - final Package? package; + final Package package; final CallbackPackageSelect? callbackPackageSelect; final double dotSize = 15.0; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); - ReceivingListRow({Key? key, this.package, this.callbackPackageSelect}) + ReceivingListRow( + {Key? key, required this.package, this.callbackPackageSelect}) : super(key: key); @override @@ -24,7 +24,7 @@ class ReceivingListRow extends StatelessWidget { return InkWell( onTap: () { if (callbackPackageSelect != null) { - callbackPackageSelect!(package!); + callbackPackageSelect!(package); return; } Navigator.push( @@ -39,36 +39,32 @@ class ReceivingListRow extends StatelessWidget { children: [ Expanded( child: new Padding( - padding: const EdgeInsets.symmetric(vertical: 16.0), + padding: const EdgeInsets.symmetric(vertical: 13.0), child: new Row( children: [ - Padding( - padding: EdgeInsets.all(5.0), - child: Icon( - MaterialCommunityIcons.inbox_arrow_down, - color: primaryColor, - )), + Icon(MaterialCommunityIcons.inbox_arrow_down, + color: primaryColor), new Expanded( - child: new Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - package!.id == null ? '' : package!.trackingID!, + child: Padding( + padding: const EdgeInsets.only(left: 15), + child: new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Text( + package.id == null ? '' : package.trackingID!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: new Text( - package!.market == null ? '' : package!.market!, - style: new TextStyle( - fontSize: 15.0, color: Colors.black), + Padding( + padding: const EdgeInsets.only(top: 5), + child: new Text( + package.market == null ? '' : package.market!, + style: new TextStyle( + fontSize: 15.0, color: Colors.black), + ), ), - ), - ], + ], + ), ), ), ], @@ -76,18 +72,20 @@ class ReceivingListRow extends StatelessWidget { ), ), Column( + crossAxisAlignment: CrossAxisAlignment.end, children: [ + Text(package.status ?? "", + style: TextStyle( + color: primaryColor, + fontSize: 15, + fontWeight: FontWeight.bold)), Padding( - padding: const EdgeInsets.all(3.0), - child: getStatus(package!.status??""), - ), - Padding( - padding: const EdgeInsets.all(0), + padding: const EdgeInsets.only(top: 5), child: new Text( - package!.currentStatusDate != null - ? dateFormat.format(package!.currentStatusDate!) + package.currentStatusDate != null + ? dateFormat.format(package.currentStatusDate!) : '', - style: new TextStyle(fontSize: 15.0, color: Colors.grey), + style: new TextStyle(fontSize: 14.0, color: Colors.grey), ), ), ], diff --git a/lib/pages/term/term_edit.dart b/lib/pages/term/term_edit.dart deleted file mode 100644 index 1d62d9a..0000000 --- a/lib/pages/term/term_edit.dart +++ /dev/null @@ -1,174 +0,0 @@ -import 'package:fcs/domain/vo/term.dart'; -import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; -import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -// import 'package:zefyrka/zefyrka.dart'; -// import 'package:zefyr/zefyr.dart'; - -typedef void ProfileCallback(); - -class TermEdit extends StatefulWidget { - final Term? term; - TermEdit({required this.term}); - @override - _TermEditState createState() => _TermEditState(); -} - -class _TermEditState extends State { - /// Allows to control the editor and the document. - // late ZefyrController _controllerEng; - // late ZefyrController _controllerMm; - - /// Zefyr editor like any other input field requires a focus node. - late FocusNode _focusNodeEng; - late FocusNode _focusNodeMm; - bool _isLoading = false; - - @override - void initState() { - super.initState(); - _isLoading = false; - - // Here we must load the document and pass it to Zefyr controller. - // _controllerEng = ZefyrController(_loadDocument(widget.term!.termEng ?? "")); - // _controllerMm = ZefyrController(_loadDocument(widget.term!.termMm ?? "")); - _focusNodeEng = FocusNode(); - _focusNodeMm = FocusNode(); - } - - /// Loads the document to be edited in Zefyr. - // NotusDocument _loadDocument(String data) { - // late NotusDocument doc; - // try { - // doc = NotusDocument.fromJson(jsonDecode(data)); - // } catch (e) {} - // if (doc == null) { - // doc = NotusDocument(); - // } - // return doc; - // } - - @override - Widget build(BuildContext context) { - final savebtn = - fcsButton(context, getLocalString(context, "btn.save"), callack: _save); - - return DefaultTabController( - length: 2, - child: LocalProgress( - inAsyncCall: _isLoading, - child: Scaffold( - appBar: AppBar( - title: LocalLargeTitle( - context, - "term", - color: primaryColor, - ), - leading: IconButton( - icon: Icon(CupertinoIcons.back, color: primaryColor, size: 25), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - shadowColor: Colors.transparent, - backgroundColor: Colors.white, - actions: [ - IconButton( - onPressed: _unfocus, - icon: Icon(Icons.check, color: primaryColor)) - ], - bottom: TabBar.secondary( - indicatorColor: primaryColor, - onTap: (index) { - if (index == 0) { - _focusNodeEng = new FocusNode(); - FocusScope.of(context).requestFocus(_focusNodeEng); - } else { - _focusNodeMm = new FocusNode(); - FocusScope.of(context).requestFocus(_focusNodeMm); - } - }, - tabs: [ - Tab( - icon: Image.asset( - 'icons/flags/png/us.png', - package: 'country_icons', - fit: BoxFit.fitWidth, - width: 25, - )), - Tab( - icon: Image.asset( - 'icons/flags/png/mm.png', - package: 'country_icons', - fit: BoxFit.fitWidth, - width: 25, - )), - ], - ), - ), - body: ListView( - children: [ - Container( - height: MediaQuery.of(context).size.height - 200, - child: TabBarView( - children: [ - const SizedBox(), - const SizedBox(), - // textEditor(_controllerEng, _focusNodeEng), - // textEditor(_controllerMm, _focusNodeMm), - ], - ), - ), - savebtn, - const SizedBox(height: 20) - ], - ), - ), - ), - ); - } - - // Widget textEditor(ZefyrController controller, FocusNode focusNode) { - // return ListView( - // children: [ - // Container( - // height: MediaQuery.of(context).size.height - 200, - // child: ZefyrEditor( - // autofocus: false, - // padding: EdgeInsets.all(16), - // controller: controller, - // focusNode: focusNode, - // ), - // ), - // SizedBox( - // height: 10, - // ) - // ], - // ); - // } - - _unfocus() { - FocusScope.of(context).unfocus(); - } - - _save() async { - setState(() { - _isLoading = true; - }); - try { - // final contentsEng = jsonEncode(_controllerEng.document); - // final contentsMm = jsonEncode(_controllerMm.document); - // // print('contents => $contentsEng'); - // TermModel termModel = Provider.of(context, listen: false); - // await termModel.saveTerm(Term(termEng: contentsEng, termMm: contentsMm)); - } catch (e) { - showMsgDialog(context, "Error", e.toString()); - } finally { - _isLoading = false; - Navigator.pop(context); - } - } -} diff --git a/lib/pages/term/term_editor.dart b/lib/pages/term/term_editor.dart new file mode 100644 index 0000000..592ff07 --- /dev/null +++ b/lib/pages/term/term_editor.dart @@ -0,0 +1,213 @@ +import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/widgets/progress.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; +import '../../domain/vo/term.dart'; +import '../main/util.dart'; +import '../widgets/local_text.dart'; + +class TermEditor extends StatefulWidget { + final Term term; + const TermEditor({super.key, required this.term}); + + @override + State createState() => _TermEditorState(); +} + +class _TermEditorState extends State { + int selectedIndex = 0; + final List _selectedIcon = [true, false]; + List icons = [ + const Icon(Icons.edit), + const Icon(Icons.preview_outlined), + ]; + bool isEdit = true; + TextEditingController mmController = TextEditingController(); + TextEditingController enController = TextEditingController(); + + bool _isLoading = false; + + @override + void initState() { + super.initState(); + enController.text = widget.term.termEng ?? ""; + mmController.text = widget.term.termMm ?? ""; + } + + @override + void dispose() { + enController.dispose(); + mmController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final toggleBtn = ToggleButtons( + direction: Axis.horizontal, + onPressed: (int index) { + setState(() { + for (int i = 0; i < _selectedIcon.length; i++) { + _selectedIcon[i] = !_selectedIcon[i]; + isEdit = (_selectedIcon[0] == true) ? true : false; + } + }); + }, + borderRadius: const BorderRadius.all(Radius.circular(5)), + borderColor: primaryColor.withOpacity(0.3), + selectedBorderColor: Colors.white, + fillColor: primaryColor, + color: primaryColor, + isSelected: _selectedIcon, + constraints: const BoxConstraints(minHeight: 20, minWidth: 40), + children: icons, + ); + + final savebtn = Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: fcsButton(context, getLocalString(context, "btn.save"), + callack: _save), + ); + + return LocalProgress( + inAsyncCall: _isLoading, + child: DefaultTabController( + length: 2, + initialIndex: selectedIndex, + child: Scaffold( + backgroundColor: Colors.white, + appBar: AppBar( + elevation: 0, + centerTitle: true, + leading: IconButton( + splashRadius: 25, + icon: const Icon(CupertinoIcons.back, + color: primaryColor, size: 25), + onPressed: () => Navigator.pop(context)), + shadowColor: Colors.transparent, + backgroundColor: Colors.white, + title: + LocalText(context, 'term', fontSize: 20, color: primaryColor), + bottom: TabBar.secondary( + indicatorColor: primaryColor, + labelColor: primaryColor, + labelStyle: + const TextStyle(fontSize: 15, fontWeight: FontWeight.bold), + unselectedLabelColor: Colors.grey, + unselectedLabelStyle: + const TextStyle(fontSize: 15, fontWeight: FontWeight.bold), + onTap: (index) { + selectedIndex = index; + }, + tabs: [Tab(text: "English"), Tab(text: "Myanmar")]), + actions: [ + Padding( + padding: const EdgeInsets.only(right: 20), child: toggleBtn) + ], + ), + body: SafeArea( + child: ScrollConfiguration( + behavior: const ScrollBehavior().copyWith(overscroll: false), + child: ListView( + children: [ + SizedBox( + height: MediaQuery.of(context).size.height - 210, + child: TabBarView( + children: [ + isEdit + ? Padding( + padding: const EdgeInsets.all(15), + child: TextField( + autofocus: true, + controller: enController, + style: TextStyle( + fontSize: 15, color: Colors.black87), + decoration: const InputDecoration( + border: InputBorder.none), + cursorColor: primaryColor, + keyboardType: TextInputType.multiline, + maxLines: null, + readOnly: isEdit ? false : true, + ), + ) + : Padding( + padding: + const EdgeInsets.only(top: 15, bottom: 15), + child: Markdown( + shrinkWrap: true, + softLineBreak: true, + physics: const BouncingScrollPhysics(), + data: enController.text + .replaceAll("\\n", '\n'), + styleSheet: MarkdownStyleSheet.fromTheme( + ThemeData( + textTheme: const TextTheme( + bodyMedium: TextStyle( + fontSize: 15, + color: Colors.black87))))), + ), + isEdit + ? Padding( + padding: const EdgeInsets.all(15), + child: TextField( + style: TextStyle( + fontSize: 14, color: Colors.black87), + autofocus: true, + controller: mmController, + decoration: const InputDecoration( + border: InputBorder.none), + cursorColor: primaryColor, + keyboardType: TextInputType.multiline, + maxLines: null, + readOnly: isEdit ? false : true, + ), + ) + : Padding( + padding: + const EdgeInsets.only(top: 15, bottom: 15), + child: Markdown( + shrinkWrap: true, + softLineBreak: true, + physics: const BouncingScrollPhysics(), + data: mmController.text + .replaceAll("\\n", '\n'), + styleSheet: MarkdownStyleSheet.fromTheme( + ThemeData( + textTheme: const TextTheme( + bodyMedium: TextStyle( + fontSize: 14, + color: Colors.black87))))), + ), + ], + ), + ), + savebtn, + const SizedBox(height: 20) + ], + ), + ), + ), + ), + ), + ); + } + + _save() async { + setState(() { + _isLoading = true; + }); + try { + // final contentsEng = jsonEncode(_controllerEng.document); + // final contentsMm = jsonEncode(_controllerMm.document); + // // print('contents => $contentsEng'); + // TermModel termModel = Provider.of(context, listen: false); + // await termModel.saveTerm(Term(termEng: contentsEng, termMm: contentsMm)); + } catch (e) { + showMsgDialog(context, "Error", e.toString()); + } finally { + _isLoading = false; + Navigator.pop(context); + } + } +} diff --git a/lib/pages/term/term_page.dart b/lib/pages/term/term_page.dart index aeb9592..f7dd29b 100644 --- a/lib/pages/term/term_page.dart +++ b/lib/pages/term/term_page.dart @@ -2,52 +2,28 @@ import 'package:fcs/domain/entities/setting.dart'; import 'package:fcs/domain/vo/term.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/model/main_model.dart'; -import 'package:fcs/pages/term/term_edit.dart'; import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:provider/provider.dart'; -// import 'package:zefyrka/zefyrka.dart'; -typedef void ProfileCallback(); +import '../main/model/language_model.dart'; +import 'term_editor.dart'; class TermPage extends StatefulWidget { - const TermPage({ - Key? key, - }) : super(key: key); + const TermPage({Key? key}) : super(key: key); @override _TermPageState createState() => _TermPageState(); } class _TermPageState extends State { - // late ZefyrController _controller; - // late FocusNode _focusNode; - // late NotusDocument document = new NotusDocument(); - bool isLoading = false; - - @override - void initState() { - super.initState(); - // _focusNode = FocusNode(); - } - - // NotusDocument _loadDocument(Setting? setting) { - // bool isEng = Provider.of(context).isEng; - // String? term = isEng ? (setting!.termsEng ?? "") : (setting!.termsMm ?? ""); - // late NotusDocument doc; - // try { - // doc = NotusDocument.fromJson(jsonDecode(term)); - // } catch (e) {} - // if (doc == null) { - // doc = NotusDocument(); - // } - // return doc; - // } - @override Widget build(BuildContext context) { + bool isEng = Provider.of(context).isEng; Setting? setting = Provider.of(context).setting; bool isEditable = context.select((MainModel m) => m.termEditable()); + String? term = isEng ? (setting!.termsEng ?? "") : (setting!.termsMm ?? ""); return Scaffold( appBar: LocalAppBar( @@ -58,20 +34,25 @@ class _TermPageState extends State { actions: isEditable ? [ IconButton( - onPressed: () => - Navigator.of(context).push(CupertinoPageRoute( - builder: (context) => - TermEdit(term: Term.fromSetting(setting!)), - )), + onPressed: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => + TermEditor(term: Term.fromSetting(setting)), + )); + }, icon: Icon(Icons.edit, color: primaryColor)) ] : [], ), - // body: ZefyrEditor( - // padding: EdgeInsets.all(16), - // controller: ZefyrController(_loadDocument(setting)), - // focusNode: _focusNode, - // ), + body: Markdown( + shrinkWrap: true, + softLineBreak: true, + physics: const BouncingScrollPhysics(), + data: term.replaceAll("\\n", '\n'), + styleSheet: MarkdownStyleSheet.fromTheme(ThemeData( + textTheme: TextTheme( + bodyMedium: TextStyle( + fontSize: isEng ? 15 : 14, color: Colors.black87))))), ); } } diff --git a/lib/pages/widgets/input_date.dart b/lib/pages/widgets/input_date.dart index 6024790..491eb41 100644 --- a/lib/pages/widgets/input_date.dart +++ b/lib/pages/widgets/input_date.dart @@ -16,6 +16,7 @@ class InputDate extends StatelessWidget { final TextInputType? textInputType; final bool autoFocus; final String dateFormatString; + final AutovalidateMode? autovalidateMode; const InputDate( {Key? key, @@ -23,6 +24,7 @@ class InputDate extends StatelessWidget { required this.iconData, required this.controller, this.validator, + this.autovalidateMode, this.maxLines = 1, this.withBorder = false, this.borderColor, @@ -126,7 +128,8 @@ class InputDate extends StatelessWidget { borderSide: BorderSide( color: borderColor ?? dangerColor, width: 1.0)), ), - validator: validator), + validator: validator, + autovalidateMode: autovalidateMode,), ); } } diff --git a/lib/pages/widgets/input_text.dart b/lib/pages/widgets/input_text.dart index 9d09b07..f6f4397 100644 --- a/lib/pages/widgets/input_text.dart +++ b/lib/pages/widgets/input_text.dart @@ -9,6 +9,7 @@ class InputText extends StatelessWidget { final IconData? iconData; final TextEditingController? controller; final FormFieldValidator? validator; + final AutovalidateMode? autovalidateMode; final int maxLines; final bool withBorder; final Color? borderColor; @@ -26,6 +27,7 @@ class InputText extends StatelessWidget { this.iconData, this.controller, this.validator, + this.autovalidateMode, this.maxLines = 1, this.withBorder = false, this.borderColor, @@ -114,7 +116,8 @@ class InputText extends StatelessWidget { borderSide: BorderSide( color: borderColor ?? dangerColor, width: 1.0)), ), - validator: validator), + validator: validator, + autovalidateMode: autovalidateMode,), ); } } diff --git a/pubspec.yaml b/pubspec.yaml index 9dcf6c6..fe2b945 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,6 +57,7 @@ dependencies: open_file: ^3.3.2 pdf: ^3.10.8 qr_flutter: ^4.1.0 + flutter_markdown: ^0.6.20+1 dev_dependencies: flutter_test: