diff --git a/lib/domain/entities/custom_duty.dart b/lib/domain/entities/custom_duty.dart index 6f033f0..9fffce6 100644 --- a/lib/domain/entities/custom_duty.dart +++ b/lib/domain/entities/custom_duty.dart @@ -14,8 +14,8 @@ class CustomDuty { factory CustomDuty.fromMap(Map map, String id) { return CustomDuty( id: id, - productType: map['product_type'], - desc: map['desc'], + productType: map['product_type'] ?? "", + desc: map['desc'] ?? "", fee: (map['fee'] ?? 0).toDouble(), ); } diff --git a/lib/domain/entities/invoice.dart b/lib/domain/entities/invoice.dart index 6bb4170..665f0b8 100644 --- a/lib/domain/entities/invoice.dart +++ b/lib/domain/entities/invoice.dart @@ -133,8 +133,9 @@ class Invoice { cargoTypesMaps.map((e) => CargoType.fromMap(e, e["id"])).toList(); var customDutiesMap = List>.from(map['custom_duties'] ?? []); - var customDuties = - customDutiesMap.map((e) => CustomDuty.fromMap(e, e["id"])).toList(); + var customDuties = customDutiesMap + .map((e) => CustomDuty.fromMap(e, e["id"] ?? "")) + .toList(); var handlingShipmentsMap = List>.from(map['handling_fee_shipments'] ?? []); var handingShipments = @@ -149,22 +150,23 @@ class Invoice { var discount = Discount.fromMap(discountMap, discountMap['id']); var paymentMaps = List>.from(map['payments'] ?? []); var payments = paymentMaps.map((e) => Payment.fromMap(e, e["id"])).toList(); + return Invoice( id: docID, - invoiceNumber: map['invoice_number'], + invoiceNumber: map['invoice_number'] ?? "", invoiceDate: invd.toDate(), - userName: map['user_name'], - fcsID: map['fcs_id'], - phoneNumber: map['phone_number'], - amount: map['amount'], + userName: map['user_name'] ?? "", + fcsID: map['fcs_id'] ?? "", + phoneNumber: map['phone_number'] ?? "", + amount: map['amount'] ?? 0, paidAmount: double.tryParse(map['paid_amount'].toString()) ?? 0, - status: map['status'], + status: map['status'] ?? "", cartons: cartons, cargoTypes: cargoTypes, shipments: handingShipments, customDuties: customDuties, - deliveryFee: map['delivery_fee'], - invoiceURL: map['invoice_url'], + deliveryFee: map['delivery_fee'] ?? 0, + invoiceURL: map['invoice_url'] ?? "", paymentMethod: paymentMethod, discount: discount, payments: payments, diff --git a/lib/domain/entities/user.dart b/lib/domain/entities/user.dart index f3fd143..9325bd5 100644 --- a/lib/domain/entities/user.dart +++ b/lib/domain/entities/user.dart @@ -109,8 +109,8 @@ class User { fcsID: map['fcs_id'], privileges: _privileges, lastMessage: map['last_message'], - userUnseenCount: map['user_unseen_count'], - fcsUnseenCount: map['fcs_unseen_count'], + userUnseenCount: map['user_unseen_count'] ?? 0, + fcsUnseenCount: map['fcs_unseen_count'] ?? 0, preferCurrency: map['preferred_currency'], lastMessageTime: _date == null ? null : _date.toDate()); } diff --git a/lib/pages/carton/cargo_type_addtion.dart b/lib/pages/carton/cargo_type_addtion.dart index 0201e9b..eb11f1e 100644 --- a/lib/pages/carton/cargo_type_addtion.dart +++ b/lib/pages/carton/cargo_type_addtion.dart @@ -2,10 +2,9 @@ import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_title.dart'; import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -99,21 +98,11 @@ class _CargoTypeAdditionState extends State { return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: - new Icon(CupertinoIcons.back, color: primaryColor, size: 30), - onPressed: () => Navigator.of(context).pop(), - ), - shadowColor: Colors.transparent, + appBar: LocalAppBar( + labelKey: 'cargo.form.title', backgroundColor: Colors.white, - title: LocalText( - context, - "cargo.form.title", - fontSize: 20, - color: primaryColor, - )), + labelColor: primaryColor, + arrowColor: primaryColor), body: Container( padding: EdgeInsets.all(8), child: ListView( diff --git a/lib/pages/carton_size/carton_size_editor.dart b/lib/pages/carton_size/carton_size_editor.dart index 4e6882b..f615a35 100644 --- a/lib/pages/carton_size/carton_size_editor.dart +++ b/lib/pages/carton_size/carton_size_editor.dart @@ -3,9 +3,8 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/length_picker.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; @@ -135,29 +134,21 @@ class _CartonSizeEditorState extends State { return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: - new Icon(CupertinoIcons.back, color: primaryColor, size: 30), - onPressed: () { - if (isDataChanged()) { - showConfirmDialog(context, "back.button_confirm", () { - Navigator.of(context).pop(); - }); - } else { - Navigator.of(context).pop(); - } - }, - ), - shadowColor: Colors.transparent, - backgroundColor: Colors.white, - title: LocalText( - context, - "box.carton_size", - fontSize: 20, - color: primaryColor, - )), + appBar: LocalAppBar( + labelKey: "box.carton_size", + backgroundColor: Colors.white, + labelColor: primaryColor, + arrowColor: primaryColor, + onBack: () { + if (isDataChanged()) { + showConfirmDialog(context, "back.button_confirm", () { + Navigator.of(context).pop(); + }); + } else { + Navigator.of(context).pop(); + } + }, + ), body: Container( padding: EdgeInsets.all(18), child: ListView( diff --git a/lib/pages/carton_size/carton_size_list.dart b/lib/pages/carton_size/carton_size_list.dart index 51c9985..71bbafc 100644 --- a/lib/pages/carton_size/carton_size_list.dart +++ b/lib/pages/carton_size/carton_size_list.dart @@ -1,7 +1,7 @@ import 'package:fcs/domain/entities/carton_size.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/local_app_bar.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -72,22 +72,11 @@ class _CartonSizeListState extends State { return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: - new Icon(CupertinoIcons.back, color: primaryColor, size: 30), - onPressed: () => Navigator.of(context).pop(), - ), - shadowColor: Colors.transparent, - backgroundColor: Colors.white, - title: LocalText( - context, - "box.carton_size.title", - fontSize: 20, - color: primaryColor, - ), - ), + appBar: LocalAppBar( + labelKey: 'box.carton_size.title', + backgroundColor: Colors.white, + labelColor: primaryColor, + arrowColor: primaryColor), body: Padding( padding: const EdgeInsets.only(left: 12.0, right: 12), child: ListView( diff --git a/lib/pages/chat/bubble.dart b/lib/pages/chat/bubble.dart index a553549..10a8b4e 100644 --- a/lib/pages/chat/bubble.dart +++ b/lib/pages/chat/bubble.dart @@ -72,27 +72,18 @@ class Bubble extends StatelessWidget { getMsg(context, icon), TextButton( style: TextButton.styleFrom( - backgroundColor:Colors.blue[50], + backgroundColor: Colors.blue[50], shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.0), - )), - onPressed: () {}, + borderRadius: BorderRadius.circular(10.0), + )), + onPressed: () { + _viewDetail(); + }, child: Text( getLocalString(context, "message.view.detail"), style: TextStyle( color: primaryColor, fontWeight: FontWeight.bold))) - // FlatButton( - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(10.0), - // ), - // color: Colors.blue[50], - // onPressed: () => _viewDetail(), - // child: Text( - // getLocalString(context, "message.view.detail"), - // style: TextStyle( - // color: primaryColor, - // fontWeight: FontWeight.bold))) ] : [ Text(isCustomer ? "FCS Team" : sender ?? "", diff --git a/lib/pages/discount/model/discount_model.dart b/lib/pages/discount/model/discount_model.dart index 77c7b32..bd5831f 100644 --- a/lib/pages/discount/model/discount_model.dart +++ b/lib/pages/discount/model/discount_model.dart @@ -82,7 +82,7 @@ class DiscountModel extends BaseModel { var snaps = await q.get(const GetOptions(source: Source.server)); var discounts = snaps.docs.map((snap) { if (snap.exists) { - var s = Discount.fromMap(snap.data as Map, snap.id); + var s = Discount.fromMap(snap.data(), snap.id); return s; } }).toList(); diff --git a/lib/pages/invoice/editor/invoice_carton_table.dart b/lib/pages/invoice/editor/invoice_carton_table.dart index 6faf7c8..09ff783 100644 --- a/lib/pages/invoice/editor/invoice_carton_table.dart +++ b/lib/pages/invoice/editor/invoice_carton_table.dart @@ -3,7 +3,6 @@ import 'package:fcs/domain/entities/rate.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/local_title.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; typedef OnSelect = Function(Carton carton, bool checked); diff --git a/lib/pages/invoice/editor/invoice_discount_list.dart b/lib/pages/invoice/editor/invoice_discount_list.dart index cbde9ed..ce77fe1 100644 --- a/lib/pages/invoice/editor/invoice_discount_list.dart +++ b/lib/pages/invoice/editor/invoice_discount_list.dart @@ -1,7 +1,7 @@ import 'package:fcs/domain/entities/discount.dart'; import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_text.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class InvoiceDiscountList extends StatelessWidget { @@ -15,24 +15,9 @@ class InvoiceDiscountList extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.pop(context), - ), - backgroundColor: primaryColor, - title: LocalText( - context, - "invoice.shipment.discount.title", - fontSize: 20, - color: Colors.white, - ), - ), - body: Padding( - padding: const EdgeInsets.all(8.0), - child: table(context), - )); + appBar: LocalAppBar(labelKey: 'invoice.shipment.discount.title'), + body: + Padding(padding: const EdgeInsets.all(8.0), child: table(context))); } Widget table(BuildContext context) { diff --git a/lib/pages/invoice/editor/invoice_editor.dart b/lib/pages/invoice/editor/invoice_editor.dart index 35e62aa..1449dc1 100644 --- a/lib/pages/invoice/editor/invoice_editor.dart +++ b/lib/pages/invoice/editor/invoice_editor.dart @@ -25,11 +25,11 @@ import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/shipment/model/shipment_model.dart'; import 'package:fcs/pages/widgets/display_text.dart'; import 'package:fcs/pages/widgets/fcs_icons.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_button.dart'; import 'package:fcs/pages/widgets/local_dropdown.dart'; import 'package:fcs/pages/widgets/local_popup_menu_button.dart'; import 'package:fcs/pages/widgets/local_popupmenu.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'; @@ -249,22 +249,23 @@ class _InvoiceEditorState extends State { ], popupMenuCallback: (p) async { if (p.id == 1) { - CustomDuty customDuty = await Navigator.of(context).push( + CargoType? customDuty = await Navigator.of(context).push( CupertinoPageRoute( builder: (context) => CustomList(selected: true))); - _addCustom(customDuty); + if (customDuty == null) return; + // _addCustom(customDuty); } else if (p.id == 2) { - Shipment shipment = await Navigator.of(context).push( + Shipment? shipment = await Navigator.of(context).push( CupertinoPageRoute( builder: (context) => InvoiceHandlingFeeList(shipments: _invoice!.shipments))); + if (shipment == null) return; _addShipment(shipment); } else if (p.id == 3) { - Discount? discount = - await Navigator.of(context).push(CupertinoPageRoute( - builder: (context) => InvoiceDiscountList( - discounts: discounts, - ))); + Discount? discount = await Navigator.of(context).push( + CupertinoPageRoute( + builder: (context) => + InvoiceDiscountList(discounts: discounts))); if (discount != null) { setState(() { _invoice!.discount = discount; @@ -314,19 +315,11 @@ class _InvoiceEditorState extends State { return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back, color: primaryColor), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - backgroundColor: Colors.white, - shadowColor: Colors.transparent, - title: LocalText(context, 'invoice.form.title', - color: primaryColor, fontSize: 20), - ), + appBar: LocalAppBar( + labelKey: 'invoice.form.title', + backgroundColor: Colors.white, + labelColor: primaryColor, + arrowColor: primaryColor), body: Padding( padding: const EdgeInsets.all(8.0), child: ListView( @@ -336,10 +329,7 @@ class _InvoiceEditorState extends State { _isNew ? Container() : statusBox, _showCartons ? cartonTable : Container(), _showCartons - ? Divider( - color: primaryColor, - thickness: 2, - ) + ? Divider(color: primaryColor, thickness: 2) : Container(), invoiceTableBox, SizedBox( diff --git a/lib/pages/invoice/editor/invoice_handling_fee_list.dart b/lib/pages/invoice/editor/invoice_handling_fee_list.dart index ed06de4..e2fbd41 100644 --- a/lib/pages/invoice/editor/invoice_handling_fee_list.dart +++ b/lib/pages/invoice/editor/invoice_handling_fee_list.dart @@ -1,5 +1,6 @@ import 'package:fcs/domain/entities/shipment.dart'; import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -19,20 +20,7 @@ class InvoiceHandlingFeeList extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.pop(context), - ), - backgroundColor: primaryColor, - title: LocalText( - context, - "invoice.shipment.handling.fee.title", - fontSize: 20, - color: Colors.white, - ), - ), + appBar: LocalAppBar(labelKey: 'invoice.shipment.handling.fee.title'), body: Padding( padding: const EdgeInsets.all(8.0), child: table(context), diff --git a/lib/pages/invoice/invoice_customer_list.dart b/lib/pages/invoice/invoice_customer_list.dart index 3df5226..cd62655 100644 --- a/lib/pages/invoice/invoice_customer_list.dart +++ b/lib/pages/invoice/invoice_customer_list.dart @@ -3,7 +3,7 @@ import 'package:fcs/domain/entities/user.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/customer/model/customer_model.dart'; import 'package:fcs/pages/invoice/editor/invoice_editor.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -44,20 +44,7 @@ class _InvoiceCustomerListState extends State { return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - title: LocalText( - context, - "customer.list.title", - fontSize: 20, - color: Colors.white, - ), - ), + appBar: LocalAppBar(labelKey: 'customer.list.title'), body: Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ @@ -83,12 +70,10 @@ class _InvoiceCustomerListState extends State { Widget _item(User customer) { return InkWell( onTap: () async { - bool created = await Navigator.of(context).push(CupertinoPageRoute( + bool? created = await Navigator.of(context).push(CupertinoPageRoute( builder: (context) => InvoiceEditor( - customer: customer, - fcsShipment: widget.fcsShipment, - ))); - if (created) { + customer: customer, fcsShipment: widget.fcsShipment))); + if (created ?? false) { _load(); } }, diff --git a/lib/pages/invoice/invoice_info.dart b/lib/pages/invoice/invoice_info.dart index d9980ec..59a1427 100644 --- a/lib/pages/invoice/invoice_info.dart +++ b/lib/pages/invoice/invoice_info.dart @@ -11,10 +11,9 @@ import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/widgets/display_text.dart'; import 'package:fcs/pages/widgets/fcs_icons.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_button.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:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -151,17 +150,11 @@ class _InvoiceInfoState extends State { return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back, color: primaryColor), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: Colors.white, - shadowColor: Colors.transparent, - title: LocalText(context, 'invoice.form.title', - color: primaryColor, fontSize: 20), - ), + appBar: LocalAppBar( + labelKey: 'invoice.form.title', + backgroundColor: Colors.white, + labelColor: primaryColor, + arrowColor: primaryColor), body: Padding( padding: const EdgeInsets.all(8.0), child: ListView( diff --git a/lib/pages/invoice/invoice_list.dart b/lib/pages/invoice/invoice_list.dart index cbb5ce3..2bc0115 100644 --- a/lib/pages/invoice/invoice_list.dart +++ b/lib/pages/invoice/invoice_list.dart @@ -1,6 +1,7 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/invoice/invoice_shipment_list.dart'; import 'package:fcs/pages/invoice/model/invoice_model.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_popup_menu_button.dart'; import 'package:fcs/pages/widgets/local_popupmenu.dart'; import 'package:fcs/pages/widgets/local_text.dart'; @@ -9,38 +10,35 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import '../../domain/entities/invoice.dart'; +import '../../pagination/paginator_listview.dart'; import 'invoice_list_row.dart'; class InvoiceList extends StatefulWidget { - final bool? forCustomer; + final bool forCustomer; - const InvoiceList({Key? key, this.forCustomer}) : super(key: key); + const InvoiceList({Key? key, required this.forCustomer}) : super(key: key); @override _InvoiceListState createState() => _InvoiceListState(); } class _InvoiceListState extends State { bool _isLoading = false; - var _controller = ScrollController(); + int _selectedIndex = 1; @override void initState() { super.initState(); - _controller.addListener(() async { - if (_controller.position.pixels == _controller.position.maxScrollExtent) { - Provider.of(context, listen: false) - .loadMore(isCustomer: widget.forCustomer!); - } - }); - - InvoiceModel invoiceModel = - Provider.of(context, listen: false); - invoiceModel.initData(widget.forCustomer!, true, false); + _init(); } - @override - void dispose() { - super.dispose(); + _init() { + var model = context.read(); + _selectedIndex = model.selectedIndex; + model.loadPaginationInvoices(_selectedIndex, widget.forCustomer); + if (mounted) { + setState(() {}); + } } @override @@ -48,102 +46,50 @@ class _InvoiceListState extends State { var invoiceModel = Provider.of(context); final popupMenu = LocalPopupMenuButton( - popmenus: [ - LocalPopupMenu( - id: 1, - textKey: "invoice.popupmenu.issused", - selected: invoiceModel.selectedIndex == 1), - LocalPopupMenu( - id: 2, - textKey: "invoice.popupmenu.paid", - selected: invoiceModel.selectedIndex == 2), - LocalPopupMenu( - id: 3, - textKey: "invoice.popupmenu.cancel", - selected: invoiceModel.selectedIndex == 3) - ], - popupMenuCallback: (p) => this.setState(() { - invoiceModel.selectedIndex = p.id; - if (p.id == 2) { - Provider.of(context, listen: false) - .initData(widget.forCustomer!, false, true); - } else if (p.id == 3) { - Provider.of(context, listen: false) - .initData(widget.forCustomer!, true, false); - } else { - Provider.of(context, listen: false) - .initData(widget.forCustomer!, true, false); - } - }), - ); + popmenus: [ + LocalPopupMenu( + id: 1, + textKey: "invoice.popupmenu.issused", + selected: invoiceModel.selectedIndex == 1), + LocalPopupMenu( + id: 2, + textKey: "invoice.popupmenu.paid", + selected: invoiceModel.selectedIndex == 2), + LocalPopupMenu( + id: 3, + textKey: "invoice.popupmenu.cancel", + selected: invoiceModel.selectedIndex == 3) + ], + popupMenuCallback: (p) { + this.setState(() { + _selectedIndex = p.id; + }); + context + .read() + .onChanged(_selectedIndex, widget.forCustomer); + }); return LocalProgress( inAsyncCall: _isLoading, - child: DefaultTabController( - length: 2, - child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - title: LocalText(context, 'invoices.title', - color: Colors.white, fontSize: 20), - actions: [popupMenu], - ), - floatingActionButton: widget.forCustomer! - ? null - : FloatingActionButton.extended( - onPressed: () { - _newInvoice(); - }, - icon: Icon(Icons.add), - label: - LocalText(context, 'invoices.add', color: Colors.white), - backgroundColor: primaryColor, - ), - body: Column( - children: [ - Expanded( - child: RefreshIndicator( - child: ListView.separated( - physics: AlwaysScrollableScrollPhysics(), - controller: _controller, - separatorBuilder: (context, index) => Divider( - color: Colors.black, - height: 1, - ), - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: invoiceModel.invoices.length, - itemBuilder: (BuildContext context, int index) { - return InvoiceListRow( - key: ValueKey(invoiceModel.invoices[index].id), - invoice: invoiceModel.invoices[index], - forCustomer: widget.forCustomer, - ); - }), - onRefresh: () => invoiceModel.refresh(), - ), + child: Scaffold( + appBar: LocalAppBar( + labelKey: 'invoices.title', actions: [popupMenu]), + floatingActionButton: (widget.forCustomer) + ? null + : FloatingActionButton.extended( + onPressed: () { + _newInvoice(); + }, + icon: Icon(Icons.add), + label: + LocalText(context, 'invoices.add', color: Colors.white), + backgroundColor: primaryColor, ), - invoiceModel.isLoading - ? Container( - padding: EdgeInsets.all(8), - color: primaryColor, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("Loading...", - style: TextStyle(color: Colors.white)), - ], - ), - ) - : Container(), - ], - )), - ), + body: PaginatorListView( + paginatorListener: invoiceModel.getInvoices!, + rowBuilder: (p) => + InvoiceListRow(invoice: p, isCustomer: widget.forCustomer), + color: primaryColor)), ); } diff --git a/lib/pages/invoice/invoice_list_row.dart b/lib/pages/invoice/invoice_list_row.dart index 0cb99ac..5ac6e37 100644 --- a/lib/pages/invoice/invoice_list_row.dart +++ b/lib/pages/invoice/invoice_list_row.dart @@ -13,8 +13,9 @@ import '../widgets/pdf_screen.dart'; class InvoiceListRow extends StatelessWidget { final dateFormatter = new DateFormat('dd MMM yyyy'); final Invoice? invoice; - final bool? forCustomer; - InvoiceListRow({Key? key, this.invoice, this.forCustomer}) : super(key: key); + final bool isCustomer; + InvoiceListRow({Key? key, this.invoice, required this.isCustomer}) + : super(key: key); @override Widget build(BuildContext context) { @@ -22,9 +23,7 @@ class InvoiceListRow extends StatelessWidget { onTap: () { Navigator.of(context).push(CupertinoPageRoute( builder: (context) => PDFScreen( - title: invoice!.invoiceNumber, - url: invoice!.invoiceURL, - ))); + title: invoice!.invoiceNumber, url: invoice!.invoiceURL))); }, child: Row( children: [ @@ -55,7 +54,7 @@ class InvoiceListRow extends StatelessWidget { new Text( invoice!.status ?? "", style: new TextStyle( - fontSize: 13.0, color: primaryColor), + fontSize: 15.0, color: primaryColor), ), new Text( invoice!.invoiceDate != null @@ -76,28 +75,25 @@ class InvoiceListRow extends StatelessWidget { ? Padding( padding: const EdgeInsets.only(left: 10.0), child: InkWell( - child: ElevatedButton( - child: Row( - children: [ - Icon( - Icons.payment, - color: primaryColor, - ), - Padding( - padding: const EdgeInsets.only(left: 3.0), - child: Text( - "Payment", - style: TextStyle(fontSize: 12, color: Colors.black), - ), - ) - ], + child: ElevatedButton.icon( + style: ElevatedButton.styleFrom( + // shape: RoundedRectangleBorder( + // borderRadius: BorderRadius.all(Radius.circular(5))), + elevation: 0, + backgroundColor: Colors.grey.shade300), + icon: Icon( + Icons.payment, + color: primaryColor, ), + label: Padding( + padding: const EdgeInsets.only(left: 3.0), + child: Text("Payment", + style: + TextStyle(fontSize: 12, color: Colors.black))), onPressed: () { Navigator.of(context).push(CupertinoPageRoute( builder: (context) => PaymentPage( - invoice: invoice, - forCustomer: forCustomer, - ))); + invoice: invoice, forCustomer: isCustomer))); }, )), ) @@ -141,7 +137,7 @@ class InvoiceListRow extends StatelessWidget { Navigator.pop(context); Navigator.of(context).push(CupertinoPageRoute( builder: (context) => - InvoiceInfo(invoice: invoice, forCustomer: forCustomer))); + InvoiceInfo(invoice: invoice, forCustomer: isCustomer))); }, ), CupertinoActionSheetAction( @@ -162,7 +158,7 @@ class InvoiceListRow extends StatelessWidget { Navigator.of(context).push(CupertinoPageRoute( builder: (context) => PaymentPage( invoice: invoice, - forCustomer: forCustomer, + forCustomer: isCustomer, ))); }, ) diff --git a/lib/pages/invoice/invoice_shipment_list.dart b/lib/pages/invoice/invoice_shipment_list.dart index 44b9726..06495c8 100644 --- a/lib/pages/invoice/invoice_shipment_list.dart +++ b/lib/pages/invoice/invoice_shipment_list.dart @@ -1,7 +1,6 @@ import 'package:fcs/domain/entities/fcs_shipment.dart'; -import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -42,39 +41,26 @@ class _InvoiceShipmentListState extends State { Widget build(BuildContext context) { return LocalProgress( inAsyncCall: _isLoading, - child: DefaultTabController( - length: 3, - child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - title: LocalText(context, "invoice.shipment.title", - fontSize: 18, color: Colors.white), - ), - body: new ListView.separated( - separatorBuilder: (context, index) => Divider( - color: Colors.black, - ), - scrollDirection: Axis.vertical, - padding: EdgeInsets.only(top: 15), - shrinkWrap: true, - itemCount: _fcsShipments.length, - itemBuilder: (BuildContext context, int index) { - return InvoiceShipmentListRow( - fcsShipment: _fcsShipments[index], - onSelect: (f) { - Navigator.of(context).push(CupertinoPageRoute( - builder: (context) => InvoiceCustomerList( - fcsShipment: f, - ))); - }, - ); - }), - ), + child: Scaffold( + appBar: LocalAppBar(labelKey: "invoice.shipment.title"), + body: new ListView.separated( + separatorBuilder: (context, index) => Divider( + color: Colors.black, + ), + scrollDirection: Axis.vertical, + padding: EdgeInsets.only(top: 15), + shrinkWrap: true, + itemCount: _fcsShipments.length, + itemBuilder: (BuildContext context, int index) { + return InvoiceShipmentListRow( + fcsShipment: _fcsShipments[index], + onSelect: (f) { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => + InvoiceCustomerList(fcsShipment: f))); + }, + ); + }), ), ); } diff --git a/lib/pages/invoice/invoice_table.dart b/lib/pages/invoice/invoice_table.dart index 0ca4b21..6e79c28 100644 --- a/lib/pages/invoice/invoice_table.dart +++ b/lib/pages/invoice/invoice_table.dart @@ -115,7 +115,7 @@ class InvoiceTable extends StatelessWidget { List dataRow = tableRows.map((r) { return Container( decoration: BoxDecoration( - border: Border(bottom: BorderSide(color: Colors.grey))), + border: Border(bottom: BorderSide(color: Colors.grey.shade300))), padding: const EdgeInsets.only( left: 5.0, right: 5.0, top: 10.0, bottom: 10.0), child: Row( @@ -164,7 +164,7 @@ class InvoiceTable extends StatelessWidget { padding: const EdgeInsets.only( left: 5.0, right: 5.0, top: 15.0, bottom: 15.0), decoration: BoxDecoration( - border: Border(bottom: BorderSide(color: Colors.grey))), + border: Border(bottom: BorderSide(color: Colors.grey.shade300))), child: Row( children: [ Expanded( diff --git a/lib/pages/invoice/model/invoice_model.dart b/lib/pages/invoice/model/invoice_model.dart index 91d1bc6..ac92bbe 100644 --- a/lib/pages/invoice/model/invoice_model.dart +++ b/lib/pages/invoice/model/invoice_model.dart @@ -7,131 +7,65 @@ import 'package:fcs/domain/constants.dart'; import 'package:fcs/domain/entities/invoice.dart'; import 'package:fcs/domain/entities/payment.dart'; import 'package:fcs/helpers/firebase_helper.dart'; -import 'package:fcs/helpers/paginator.dart'; import 'package:fcs/pages/main/model/base_model.dart'; import 'package:logging/logging.dart'; import 'package:path/path.dart' as Path; +import '../../../pagination/paginator_listener.dart'; + class InvoiceModel extends BaseModel { final log = Logger('InvoiceModel'); - - StreamSubscription>>? listener; - - List _invoices = []; - - List get invoices => - _selectedIndex == 1 ? _invoices : List.from(_paginator!.values); - - Paginator? _paginator; - - bool endOfPaidInvoices = false; - bool isLoading = false; - int _selectedIndex = 1; - - set selectedIndex(int index) { - _selectedIndex = index; - notifyListeners(); - } - - int get selectedIndex => _selectedIndex; - - @override - void privilegeChanged() { - super.privilegeChanged(); - } - - initData(bool forCustomer, bool isCanceled, bool isPaid) { - _loadInvoices(forCustomer); - - if (_paginator != null) _paginator!.close(); - _paginator = _getPaginator(forCustomer, isCanceled, isPaid); - _paginator!.load(onFinished: () { - notifyListeners(); - }); - } - - Future _loadInvoices(bool forCustomer) async { - if (user == null) return; - if (!forCustomer && !user!.hasInvoices()) return; - String path = "/$invoices_collection"; - if (listener != null) listener!.cancel(); - _invoices = []; - - try { - var q = FirebaseFirestore.instance - .collection("$path") - .where("status", isEqualTo: invoice_issued_status) - .where("is_deleted", isEqualTo: false); - - if (forCustomer) { - q = q.where("user_id", isEqualTo: user!.id); - } - - listener = q.snapshots().listen((QuerySnapshot snapshot) { - _invoices.clear(); - _invoices = snapshot.docs.map((documentSnapshot) { - var s = Invoice.fromMap( - documentSnapshot.data() as Map, - documentSnapshot.id); - return s; - }).toList(); - notifyListeners(); - }); - } catch (e) { - log.warning("Error!! $e"); - } - } - - Paginator _getPaginator(bool isCustomer, bool isCanceled, bool isPaid) { - if (!isCustomer) { - if (user == null || !(user!.hasInvoices())) throw "No privilege"; - } - var pageQuery = FirebaseFirestore.instance - .collection("/$invoices_collection") - .where("is_deleted", isEqualTo: false); - if (isCustomer) { - pageQuery = pageQuery.where("user_id", isEqualTo: user!.id); - } - if (isCanceled) { - pageQuery = pageQuery.where("status", isEqualTo: invoice_cancel_status); - } - if (isPaid) { - pageQuery = pageQuery.where("status", isEqualTo: invoice_paid_status); - } - - pageQuery = pageQuery.orderBy("created_at", descending: true); - var paginator = new Paginator(pageQuery, rowPerLoad: 20, toObj: (data, id) { - return Invoice.fromMap(data, id); - }); - return paginator; - } - - Future loadMore({bool? isCustomer}) async { - if (_paginator!.ended || _selectedIndex == 1) - return; // when paid menu is not selected return - isLoading = true; - notifyListeners(); - await _paginator!.load(onFinished: () { - isLoading = false; - notifyListeners(); - }); - } - - Future refresh({bool? isCustomer}) async { - if (_selectedIndex == 1) return; // when paid menu is not selected return - await _paginator!.refresh(onFinished: () { - notifyListeners(); - }); - } + PaginatorListener? getInvoices; + int selectedIndex = 1; void initUser(user) { super.initUser(user); } logout() async { - if (_paginator != null) _paginator!.close(); - if (listener != null) await listener!.cancel(); - _invoices = []; + getInvoices?.close(); + } + + onChanged(int index, bool isCustomer) { + selectedIndex = index; + loadPaginationInvoices(index, isCustomer); + notifyListeners(); + } + + Future loadPaginationInvoices(int index, bool isCustomer) async { + if (user == null) return; + if (!isCustomer && !user!.hasInvoices()) return; + + String path = "/$invoices_collection"; + Query col = FirebaseFirestore.instance.collection(path); + Query pageQuery = FirebaseFirestore.instance.collection(path); + + if (isCustomer) { + col = col.where("user_id", isEqualTo: user!.id); + pageQuery = pageQuery.where("user_id", isEqualTo: user!.id); + } + + if (index == 1) { + col = col.where("status", isEqualTo: invoice_issued_status); + pageQuery = pageQuery.where("status", isEqualTo: invoice_issued_status); + } + + if (index == 2) { + col = col.where("status", isEqualTo: invoice_paid_status); + pageQuery = pageQuery.where("status", isEqualTo: invoice_paid_status); + } + + if (index == 3) { + col = col.where("status", isEqualTo: invoice_cancel_status); + pageQuery = pageQuery.where("status", isEqualTo: invoice_cancel_status); + } + + pageQuery = pageQuery.orderBy("created_at", descending: true); + + getInvoices?.close(); + getInvoices = PaginatorListener( + col, pageQuery, (data, id) => Invoice.fromMap(data, id), + rowPerLoad: 30); } Future getInvoice(String id) async { @@ -140,7 +74,7 @@ class InvoiceModel extends BaseModel { var ref = FirebaseFirestore.instance.collection("$path").doc(id); var snap = await ref.get(const GetOptions(source: Source.server)); if (snap.exists) { - var s = Invoice.fromMap(snap.data as Map, snap.id); + var s = Invoice.fromMap(snap.data() as Map, snap.id); return s; } } catch (e) { diff --git a/lib/pages/invoice/payment/payment_page.dart b/lib/pages/invoice/payment/payment_page.dart index c17e966..e965a6a 100644 --- a/lib/pages/invoice/payment/payment_page.dart +++ b/lib/pages/invoice/payment/payment_page.dart @@ -4,16 +4,15 @@ import 'package:fcs/domain/constants.dart'; import 'package:fcs/domain/entities/invoice.dart'; import 'package:fcs/domain/entities/payment.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/localization/app_translations.dart'; import 'package:fcs/pages/invoice/model/invoice_model.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/widgets/img_picker.dart'; import 'package:fcs/pages/widgets/input_text.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/local_button.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/local_title.dart'; import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; @@ -51,8 +50,9 @@ class _PaymentPageState extends State { InvoiceModel invoiceModel = Provider.of(context, listen: false); Invoice? i = await invoiceModel.getInvoice(_invoice.id!); + if (i == null) return; setState(() { - _invoice = i!; + _invoice = i; }); } @@ -90,15 +90,11 @@ class _PaymentPageState extends State { return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - title: Text(AppTranslations.of(context)!.text("pm_.title")), - ), + appBar: LocalAppBar( + labelKey: 'pm_.title', + backgroundColor: Colors.white, + labelColor: primaryColor, + arrowColor: primaryColor), body: ListView( padding: const EdgeInsets.all(10.0), children: [ diff --git a/lib/pages/invoice/widgets.dart b/lib/pages/invoice/widgets.dart index d631d46..bdeed89 100644 --- a/lib/pages/invoice/widgets.dart +++ b/lib/pages/invoice/widgets.dart @@ -17,7 +17,11 @@ Widget getInvoiceStatus(BuildContext context, Invoice invoice) { ), Padding( padding: const EdgeInsets.only(left: 8.0), - child: Chip(label: Text(invoice.status ?? "")), + child: Chip( + shape: const StadiumBorder( + side: BorderSide(color: Colors.transparent)), + backgroundColor: Colors.grey.withOpacity(0.3), + label: Text(invoice.status ?? "")), ), ], ); diff --git a/lib/pages/main/util.dart b/lib/pages/main/util.dart index 9c5b102..63751ac 100644 --- a/lib/pages/main/util.dart +++ b/lib/pages/main/util.dart @@ -344,32 +344,29 @@ Widget fcsButton(BuildContext context, String text, return Container( padding: EdgeInsets.only(left: 10, right: 10, top: 10), - child: Container( + child: SizedBox( height: 45.0, - decoration: BoxDecoration( - color: primaryColor, - shape: BoxShape.rectangle, - ), - child: ButtonTheme( - minWidth: 900.0, - height: 100.0, - child: TextButton( - 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), - ], - ), + 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), + ], ), ), ), diff --git a/lib/pages/market/market_editor.dart b/lib/pages/market/market_editor.dart index 6e60ea6..935f968 100644 --- a/lib/pages/market/market_editor.dart +++ b/lib/pages/market/market_editor.dart @@ -6,7 +6,6 @@ import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/local_app_bar.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:provider/provider.dart'; diff --git a/lib/pages/package/model/package_model.dart b/lib/pages/package/model/package_model.dart index 0f50b04..6b21260 100644 --- a/lib/pages/package/model/package_model.dart +++ b/lib/pages/package/model/package_model.dart @@ -21,30 +21,21 @@ class PackageModel extends BaseModel { PaginatorListener? activePackages; bool isLoading = false; - int _menuSelectedIndex = 1; + int selectedIndex = 1; - set menuSelectedIndex(int index) { - _menuSelectedIndex = index; - - _loadPaginationPackages(_menuSelectedIndex == 2); - _loadPaginationCustomerPackages(_menuSelectedIndex == 2); - - notifyListeners(); - } - - int get menuSelectedIndex => _menuSelectedIndex; - - void privilegeChanged() { - if (user != null) { - _initData(); + initData(int index, bool isCustomer) { + selectedIndex = index; + if (isCustomer) { + _loadPaginationCustomerPackages(selectedIndex == 2); + } else { + _loadPaginationPackages(selectedIndex == 2); } } - Future _initData() async { - _menuSelectedIndex = 1; - _loadPaginationPackages(_menuSelectedIndex == 2); - _loadPaginationCustomerPackages(_menuSelectedIndex == 2); - _loadPaginationActivePackages(); + void privilegeChanged() { + if (user != null) { + _loadPaginationActivePackages(); + } } @override @@ -54,6 +45,16 @@ class PackageModel extends BaseModel { if (activePackages != null) activePackages!.close(); } + onChanged(int index, bool isCustomer) { + selectedIndex = index; + if (isCustomer) { + _loadPaginationCustomerPackages(selectedIndex == 2); + } else { + _loadPaginationPackages(selectedIndex == 2); + } + notifyListeners(); + } + _loadPaginationPackages(bool isDelivered) { if (user == null) return; if (!((user!.hasPackages() || @@ -78,7 +79,6 @@ class PackageModel extends BaseModel { _loadPaginationCustomerPackages(bool isDelivered) { if (user == null) return; String path = "/$packages_collection"; - Query col = FirebaseFirestore.instance .collection(path) .where("is_delivered", isEqualTo: isDelivered) diff --git a/lib/pages/package/package_list.dart b/lib/pages/package/package_list.dart index 1c59a02..0702d07 100644 --- a/lib/pages/package/package_list.dart +++ b/lib/pages/package/package_list.dart @@ -23,12 +23,24 @@ class PackageList extends StatefulWidget { class _PackageListState extends State { bool _isLoading = false; + int _selectedIndex = 1; @override void initState() { + _init(); super.initState(); } + _init() { + var model = context.read(); + _selectedIndex = model.selectedIndex; + model.initData(_selectedIndex, widget.forCustomer); + + if (mounted) { + setState(() {}); + } + } + @override Widget build(BuildContext context) { var packageModel = Provider.of(context); @@ -37,20 +49,24 @@ class _PackageListState extends State { : packageModel.packages; final popupMenu = LocalPopupMenuButton( - popmenus: [ - LocalPopupMenu( - id: 1, - textKey: "package.popupmenu.active", - selected: packageModel.menuSelectedIndex == 1), - LocalPopupMenu( - id: 2, - textKey: "package.popupmenu.delivered", - selected: packageModel.menuSelectedIndex == 2) - ], - popupMenuCallback: (p) => this.setState(() { - packageModel.menuSelectedIndex = p.id; - }), - ); + popmenus: [ + LocalPopupMenu( + id: 1, + textKey: "package.popupmenu.active", + selected: packageModel.selectedIndex == 1), + LocalPopupMenu( + id: 2, + textKey: "package.popupmenu.delivered", + selected: packageModel.selectedIndex == 2) + ], + popupMenuCallback: (p) { + this.setState(() { + _selectedIndex = p.id; + }); + context + .read() + .onChanged(_selectedIndex, widget.forCustomer); + }); return LocalProgress( inAsyncCall: _isLoading, diff --git a/lib/pages/rates/custom_row.dart b/lib/pages/rates/custom_row.dart index 359c1b8..680369a 100644 --- a/lib/pages/rates/custom_row.dart +++ b/lib/pages/rates/custom_row.dart @@ -1,7 +1,6 @@ import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/widgets/local_text.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart'; diff --git a/lib/pages/signin/invitation_request_page.dart b/lib/pages/signin/invitation_request_page.dart index 3fe329b..64545c6 100644 --- a/lib/pages/signin/invitation_request_page.dart +++ b/lib/pages/signin/invitation_request_page.dart @@ -1,10 +1,9 @@ import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/main/util.dart'; +import 'package:fcs/pages/widgets/local_app_bar.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:flutter/services.dart'; import 'package:provider/provider.dart'; import '../../helpers/theme.dart'; @@ -29,14 +28,7 @@ class _RequestInvitationPageState extends State { return LocalProgress( inAsyncCall: _isLoading, child: new Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - ), + appBar: LocalAppBar(), body: _buildBody(context), ), ); @@ -91,6 +83,11 @@ class _RequestInvitationPageState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(3))), + backgroundColor: primaryColor), onPressed: _request, child: Text(getLocalString(context, "invite.request")), ) diff --git a/lib/pages/signin/signin_logic.dart b/lib/pages/signin/signin_logic.dart index b0d788e..d0884c5 100644 --- a/lib/pages/signin/signin_logic.dart +++ b/lib/pages/signin/signin_logic.dart @@ -4,7 +4,6 @@ import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/signin/invitation_request_page.dart'; import 'package:fcs/pages/signin/signup_page.dart'; import 'package:flutter/cupertino.dart'; -import 'package:flutter/widgets.dart'; import 'package:provider/provider.dart'; navigateAfterAuthVerified(BuildContext context) async { diff --git a/lib/pages/signin/signin_page.dart b/lib/pages/signin/signin_page.dart index 5c72ec9..2153805 100644 --- a/lib/pages/signin/signin_page.dart +++ b/lib/pages/signin/signin_page.dart @@ -3,11 +3,11 @@ import 'package:fcs/domain/entities/auth_result.dart'; import 'package:fcs/domain/entities/auth_status.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/signin/signin_logic.dart'; +import 'package:fcs/pages/widgets/local_app_bar.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:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; @@ -40,17 +40,7 @@ class _SigninPageState extends State { Widget build(BuildContext context) { return LocalProgress( inAsyncCall: _isLoading, - child: new Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - ), - body: _buildLogin(context), - ), + child: new Scaffold(appBar: LocalAppBar(), body: _buildLogin(context)), ); } diff --git a/lib/pages/signin/signup_page.dart b/lib/pages/signin/signup_page.dart index 04a08c8..bf18552 100644 --- a/lib/pages/signin/signup_page.dart +++ b/lib/pages/signin/signup_page.dart @@ -1,10 +1,9 @@ import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/main/util.dart'; +import 'package:fcs/pages/widgets/local_app_bar.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:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; @@ -30,16 +29,7 @@ class _SignupPageState extends State { return LocalProgress( inAsyncCall: _isLoading, child: new Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon( - CupertinoIcons.back, - ), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - ), + appBar: LocalAppBar(), body: _buildBody(context), ), ); diff --git a/lib/pages/signin/sms_code_page.dart b/lib/pages/signin/sms_code_page.dart index 8fc50c3..3cb3515 100644 --- a/lib/pages/signin/sms_code_page.dart +++ b/lib/pages/signin/sms_code_page.dart @@ -5,9 +5,9 @@ import 'package:fcs/domain/entities/auth_status.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/signin/signin_logic.dart'; import 'package:fcs/pages/main/util.dart'; +import 'package:fcs/pages/widgets/local_app_bar.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:pin_input_text_field/pin_input_text_field.dart'; import 'package:provider/provider.dart'; @@ -67,14 +67,7 @@ class _SmsCodePageState extends State { return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( - appBar: AppBar( - centerTitle: true, - leading: new IconButton( - icon: new Icon(CupertinoIcons.back), - onPressed: () => Navigator.of(context).pop(), - ), - backgroundColor: primaryColor, - ), + appBar: LocalAppBar(), body: ListView( padding: EdgeInsets.only(top: 5, left: 5, right: 5), children: [ @@ -129,29 +122,21 @@ class _SmsCodePageState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: - canResend ? Colors.white : Colors.grey, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.0), - side: BorderSide( - color: canResend - ? primaryColor - : Colors.grey.shade400))), - onPressed: canResend ? _resend : null, - // color: canResend ? Colors.white : Colors.grey, - child: LocalText(context, 'sms.resend', - fontSize: 16, - color: canResend - ? primaryColor - : Colors.grey.shade400), - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(10.0), - // side: BorderSide( - // color: canResend - // ? primaryColor - // : Colors.grey.shade400)), - ), + style: ElevatedButton.styleFrom( + backgroundColor: + canResend ? Colors.white : Colors.grey, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0), + side: BorderSide( + color: canResend + ? primaryColor + : Colors.grey.shade400))), + onPressed: canResend ? _resend : null, + child: LocalText(context, 'sms.resend', + fontSize: 16, + color: canResend + ? primaryColor + : Colors.grey.shade400)), InkWell( onTap: allNumberEntered ? _verify : null, child: CircleAvatar( @@ -220,19 +205,4 @@ class _SmsCodePageState extends State { _isLoading = false; }); } - - _completeResend() { - setState(() { - _isLoading = false; - _start = resend_count_sec; - canResend = false; - startTimer(); - }); - } - - _completeVerify() { - setState(() { - _isLoading = false; - }); - } } diff --git a/lib/pages/widgets/pdf_screen.dart b/lib/pages/widgets/pdf_screen.dart index d0490c3..4a785e0 100644 --- a/lib/pages/widgets/pdf_screen.dart +++ b/lib/pages/widgets/pdf_screen.dart @@ -4,8 +4,8 @@ import 'dart:io'; import 'package:fcs/helpers/cache_mgr.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/util.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; import 'package:fcs/pages/widgets/progress.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_pdfview/flutter_pdfview.dart'; import 'package:share/share.dart'; @@ -54,17 +54,12 @@ class _PDFScreenState extends State with WidgetsBindingObserver { return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( - appBar: AppBar( - centerTitle: true, + appBar: LocalAppBar( backgroundColor: Colors.white, - shadowColor: Colors.transparent, - title: - Text(widget.title ?? "", style: TextStyle(color: primaryColor)), - leading: new IconButton( - icon: new Icon(CupertinoIcons.back, color: primaryColor), - onPressed: () => Navigator.of(context).pop(), - ), - actions: [ + arrowColor: primaryColor, + titleWidget: Text(widget.title ?? "", + style: TextStyle(color: primaryColor, fontSize: 20)), + actions: [ IconButton( icon: Icon( Icons.share, @@ -89,7 +84,7 @@ class _PDFScreenState extends State with WidgetsBindingObserver { fitPolicy: FitPolicy.BOTH, preventLinkNavigation: false, // if set to true the link is handled in flutter - onRender: (int?_pages) { + onRender: (int? _pages) { print(('pages => $pages')); setState(() { pages = _pages!;