From 23877bb83caf28ff43db1c9b78032d17b51cd2df Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 20 Aug 2018 11:26:40 -0700 Subject: [PATCH] Optimizations --- lib/ui/client/edit/client_edit_details.dart | 1 + lib/ui/client/view/client_view_vm.dart | 21 ++++++---- lib/ui/dashboard/dashboard_vm.dart | 25 +++++++++--- lib/ui/invoice/view/invoice_view_vm.dart | 45 +++++++++++++-------- lib/ui/product/product_list_vm.dart | 10 +++++ 5 files changed, 73 insertions(+), 29 deletions(-) diff --git a/lib/ui/client/edit/client_edit_details.dart b/lib/ui/client/edit/client_edit_details.dart index d55a20dbe..de9eff8c5 100644 --- a/lib/ui/client/edit/client_edit_details.dart +++ b/lib/ui/client/edit/client_edit_details.dart @@ -3,6 +3,7 @@ import 'package:flutter/services.dart'; import 'package:invoiceninja_flutter/data/models/entities.dart'; import 'package:invoiceninja_flutter/ui/app/forms/custom_field.dart'; import 'package:invoiceninja_flutter/ui/client/edit/client_edit_vm.dart'; +import 'package:invoiceninja_flutter/utils/formatting.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/ui/app/form_card.dart'; diff --git a/lib/ui/client/view/client_view_vm.dart b/lib/ui/client/view/client_view_vm.dart index b4472de11..b25a91b98 100644 --- a/lib/ui/client/view/client_view_vm.dart +++ b/lib/ui/client/view/client_view_vm.dart @@ -22,6 +22,7 @@ class ClientViewScreen extends StatelessWidget { @override Widget build(BuildContext context) { return StoreConnector( + distinct: true, converter: (Store store) { return ClientViewVM.fromStore(store); }, @@ -85,10 +86,9 @@ class ClientViewVM { client: client, context: context, completer: completer)); completer.future.then((client) { Scaffold.of(context).showSnackBar(SnackBar( - content: SnackBarRow( - message: - AppLocalization.of(context).updatedClient, - ))); + content: SnackBarRow( + message: AppLocalization.of(context).updatedClient, + ))); }); }, onInvoicesPressed: (BuildContext context) { @@ -104,8 +104,7 @@ class ClientViewVM { switch (action) { case EntityAction.archive: store.dispatch(ArchiveClientRequest( - popCompleter( - context, localization.archivedClient), + popCompleter(context, localization.archivedClient), client.id)); break; case EntityAction.delete: @@ -115,11 +114,17 @@ class ClientViewVM { break; case EntityAction.restore: store.dispatch(RestoreClientRequest( - snackBarCompleter( - context, localization.restoredClient), + snackBarCompleter(context, localization.restoredClient), client.id)); break; } }); } + + @override + bool operator ==(dynamic other) => + client == other.client && company == other.company; + + @override + int get hashCode => client.hashCode ^ company.hashCode; } diff --git a/lib/ui/dashboard/dashboard_vm.dart b/lib/ui/dashboard/dashboard_vm.dart index fb77b6e96..a7d4a47a8 100644 --- a/lib/ui/dashboard/dashboard_vm.dart +++ b/lib/ui/dashboard/dashboard_vm.dart @@ -20,9 +20,10 @@ class DashboardBuilder extends StatelessWidget { @override Widget build(BuildContext context) { return StoreConnector( + distinct: true, converter: DashboardVM.fromStore, - builder: (context, vm) { - return DashboardView(viewModel: vm); + builder: (context, viewModel) { + return DashboardView(viewModel: viewModel); }, ); } @@ -30,17 +31,17 @@ class DashboardBuilder extends StatelessWidget { class DashboardVM { final DashboardState dashboardState; - final bool isLoading; - final Function(BuildContext) onRefreshed; final String filter; final List filteredList; + final bool isLoading; + final Function(BuildContext) onRefreshed; DashboardVM({ @required this.dashboardState, @required this.isLoading, - @required this.onRefreshed, @required this.filter, @required this.filteredList, + @required this.onRefreshed, }); static DashboardVM fromStore(Store store) { @@ -66,4 +67,18 @@ class DashboardVM { memoizedFilteredSelector(filter, state.selectedCompanyState), ); } + + @override + bool operator ==(dynamic other) => + dashboardState == other.dashboardState && + isLoading == other.isLoading && + filter == other.filter && + filteredList == other.filteredList; + + @override + int get hashCode => + dashboardState.hashCode ^ + isLoading.hashCode ^ + filter.hashCode ^ + filteredList.hashCode; } diff --git a/lib/ui/invoice/view/invoice_view_vm.dart b/lib/ui/invoice/view/invoice_view_vm.dart index 2081cfa21..a05429518 100644 --- a/lib/ui/invoice/view/invoice_view_vm.dart +++ b/lib/ui/invoice/view/invoice_view_vm.dart @@ -23,12 +23,13 @@ class InvoiceViewScreen extends StatelessWidget { @override Widget build(BuildContext context) { return StoreConnector( + distinct: true, converter: (Store store) { return InvoiceViewVM.fromStore(store); }, - builder: (context, vm) { + builder: (context, viewModel) { return InvoiceView( - viewModel: vm, + viewModel: viewModel, ); }, ); @@ -39,24 +40,24 @@ class InvoiceViewVM { final CompanyEntity company; final InvoiceEntity invoice; final ClientEntity client; + final bool isSaving; + final bool isDirty; final Function(BuildContext, EntityAction) onActionSelected; final Function(BuildContext, [InvoiceItemEntity]) onEditPressed; final Function(BuildContext) onClientPressed; final Function(BuildContext) onRefreshed; final Function onBackPressed; - final bool isSaving; - final bool isDirty; InvoiceViewVM({ @required this.company, @required this.invoice, @required this.client, + @required this.isSaving, + @required this.isDirty, @required this.onActionSelected, @required this.onEditPressed, @required this.onBackPressed, @required this.onClientPressed, - @required this.isSaving, - @required this.isDirty, @required this.onRefreshed, }); @@ -107,33 +108,29 @@ class InvoiceViewVM { break; case EntityAction.markSent: store.dispatch(MarkSentInvoiceRequest( - snackBarCompleter( - context, localization.markedInvoiceAsSent), + snackBarCompleter(context, localization.markedInvoiceAsSent), invoice.id)); break; case EntityAction.emailInvoice: store.dispatch(ShowEmailInvoice( - completer: snackBarCompleter( - context, localization.emailedInvoice), + completer: + snackBarCompleter(context, localization.emailedInvoice), invoice: invoice, context: context)); break; case EntityAction.archive: store.dispatch(ArchiveInvoiceRequest( - popCompleter( - context, localization.archivedInvoice), + popCompleter(context, localization.archivedInvoice), invoice.id)); break; case EntityAction.delete: store.dispatch(DeleteInvoiceRequest( - popCompleter( - context, localization.deletedInvoice), + popCompleter(context, localization.deletedInvoice), invoice.id)); break; case EntityAction.restore: store.dispatch(RestoreInvoiceRequest( - snackBarCompleter( - context, localization.restoredInvoice), + snackBarCompleter(context, localization.restoredInvoice), invoice.id)); break; case EntityAction.clone: @@ -144,4 +141,20 @@ class InvoiceViewVM { } }); } + + @override + bool operator ==(dynamic other) => + client == other.client && + company == other.company && + invoice == other.invoice && + isSaving == other.isSaving && + isDirty == other.isDirty; + + @override + int get hashCode => + client.hashCode ^ + company.hashCode ^ + invoice.hashCode ^ + isSaving.hashCode ^ + isDirty.hashCode; } diff --git a/lib/ui/product/product_list_vm.dart b/lib/ui/product/product_list_vm.dart index 734e98069..d36fc688e 100644 --- a/lib/ui/product/product_list_vm.dart +++ b/lib/ui/product/product_list_vm.dart @@ -19,6 +19,7 @@ class ProductListBuilder extends StatelessWidget { @override Widget build(BuildContext context) { return StoreConnector( + //distinct: true, converter: ProductListVM.fromStore, builder: (context, vm) { return ProductList( @@ -132,4 +133,13 @@ class ProductListVM { } }); } + + /* + @override + bool operator ==(dynamic other) => + client == other.client && company == other.company; + + @override + int get hashCode => client.hashCode ^ company.hashCode; + */ }