Optimizations
This commit is contained in:
parent
e481bbf671
commit
23877bb83c
|
|
@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/forms/custom_field.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/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/utils/localization.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
|
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ class ClientViewScreen extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return StoreConnector<AppState, ClientViewVM>(
|
return StoreConnector<AppState, ClientViewVM>(
|
||||||
|
distinct: true,
|
||||||
converter: (Store<AppState> store) {
|
converter: (Store<AppState> store) {
|
||||||
return ClientViewVM.fromStore(store);
|
return ClientViewVM.fromStore(store);
|
||||||
},
|
},
|
||||||
|
|
@ -85,10 +86,9 @@ class ClientViewVM {
|
||||||
client: client, context: context, completer: completer));
|
client: client, context: context, completer: completer));
|
||||||
completer.future.then((client) {
|
completer.future.then((client) {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
Scaffold.of(context).showSnackBar(SnackBar(
|
||||||
content: SnackBarRow(
|
content: SnackBarRow(
|
||||||
message:
|
message: AppLocalization.of(context).updatedClient,
|
||||||
AppLocalization.of(context).updatedClient,
|
)));
|
||||||
)));
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onInvoicesPressed: (BuildContext context) {
|
onInvoicesPressed: (BuildContext context) {
|
||||||
|
|
@ -104,8 +104,7 @@ class ClientViewVM {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case EntityAction.archive:
|
case EntityAction.archive:
|
||||||
store.dispatch(ArchiveClientRequest(
|
store.dispatch(ArchiveClientRequest(
|
||||||
popCompleter(
|
popCompleter(context, localization.archivedClient),
|
||||||
context, localization.archivedClient),
|
|
||||||
client.id));
|
client.id));
|
||||||
break;
|
break;
|
||||||
case EntityAction.delete:
|
case EntityAction.delete:
|
||||||
|
|
@ -115,11 +114,17 @@ class ClientViewVM {
|
||||||
break;
|
break;
|
||||||
case EntityAction.restore:
|
case EntityAction.restore:
|
||||||
store.dispatch(RestoreClientRequest(
|
store.dispatch(RestoreClientRequest(
|
||||||
snackBarCompleter(
|
snackBarCompleter(context, localization.restoredClient),
|
||||||
context, localization.restoredClient),
|
|
||||||
client.id));
|
client.id));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(dynamic other) =>
|
||||||
|
client == other.client && company == other.company;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => client.hashCode ^ company.hashCode;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,10 @@ class DashboardBuilder extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return StoreConnector<AppState, DashboardVM>(
|
return StoreConnector<AppState, DashboardVM>(
|
||||||
|
distinct: true,
|
||||||
converter: DashboardVM.fromStore,
|
converter: DashboardVM.fromStore,
|
||||||
builder: (context, vm) {
|
builder: (context, viewModel) {
|
||||||
return DashboardView(viewModel: vm);
|
return DashboardView(viewModel: viewModel);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -30,17 +31,17 @@ class DashboardBuilder extends StatelessWidget {
|
||||||
|
|
||||||
class DashboardVM {
|
class DashboardVM {
|
||||||
final DashboardState dashboardState;
|
final DashboardState dashboardState;
|
||||||
final bool isLoading;
|
|
||||||
final Function(BuildContext) onRefreshed;
|
|
||||||
final String filter;
|
final String filter;
|
||||||
final List<BaseEntity> filteredList;
|
final List<BaseEntity> filteredList;
|
||||||
|
final bool isLoading;
|
||||||
|
final Function(BuildContext) onRefreshed;
|
||||||
|
|
||||||
DashboardVM({
|
DashboardVM({
|
||||||
@required this.dashboardState,
|
@required this.dashboardState,
|
||||||
@required this.isLoading,
|
@required this.isLoading,
|
||||||
@required this.onRefreshed,
|
|
||||||
@required this.filter,
|
@required this.filter,
|
||||||
@required this.filteredList,
|
@required this.filteredList,
|
||||||
|
@required this.onRefreshed,
|
||||||
});
|
});
|
||||||
|
|
||||||
static DashboardVM fromStore(Store<AppState> store) {
|
static DashboardVM fromStore(Store<AppState> store) {
|
||||||
|
|
@ -66,4 +67,18 @@ class DashboardVM {
|
||||||
memoizedFilteredSelector(filter, state.selectedCompanyState),
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,13 @@ class InvoiceViewScreen extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return StoreConnector<AppState, InvoiceViewVM>(
|
return StoreConnector<AppState, InvoiceViewVM>(
|
||||||
|
distinct: true,
|
||||||
converter: (Store<AppState> store) {
|
converter: (Store<AppState> store) {
|
||||||
return InvoiceViewVM.fromStore(store);
|
return InvoiceViewVM.fromStore(store);
|
||||||
},
|
},
|
||||||
builder: (context, vm) {
|
builder: (context, viewModel) {
|
||||||
return InvoiceView(
|
return InvoiceView(
|
||||||
viewModel: vm,
|
viewModel: viewModel,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -39,24 +40,24 @@ class InvoiceViewVM {
|
||||||
final CompanyEntity company;
|
final CompanyEntity company;
|
||||||
final InvoiceEntity invoice;
|
final InvoiceEntity invoice;
|
||||||
final ClientEntity client;
|
final ClientEntity client;
|
||||||
|
final bool isSaving;
|
||||||
|
final bool isDirty;
|
||||||
final Function(BuildContext, EntityAction) onActionSelected;
|
final Function(BuildContext, EntityAction) onActionSelected;
|
||||||
final Function(BuildContext, [InvoiceItemEntity]) onEditPressed;
|
final Function(BuildContext, [InvoiceItemEntity]) onEditPressed;
|
||||||
final Function(BuildContext) onClientPressed;
|
final Function(BuildContext) onClientPressed;
|
||||||
final Function(BuildContext) onRefreshed;
|
final Function(BuildContext) onRefreshed;
|
||||||
final Function onBackPressed;
|
final Function onBackPressed;
|
||||||
final bool isSaving;
|
|
||||||
final bool isDirty;
|
|
||||||
|
|
||||||
InvoiceViewVM({
|
InvoiceViewVM({
|
||||||
@required this.company,
|
@required this.company,
|
||||||
@required this.invoice,
|
@required this.invoice,
|
||||||
@required this.client,
|
@required this.client,
|
||||||
|
@required this.isSaving,
|
||||||
|
@required this.isDirty,
|
||||||
@required this.onActionSelected,
|
@required this.onActionSelected,
|
||||||
@required this.onEditPressed,
|
@required this.onEditPressed,
|
||||||
@required this.onBackPressed,
|
@required this.onBackPressed,
|
||||||
@required this.onClientPressed,
|
@required this.onClientPressed,
|
||||||
@required this.isSaving,
|
|
||||||
@required this.isDirty,
|
|
||||||
@required this.onRefreshed,
|
@required this.onRefreshed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -107,33 +108,29 @@ class InvoiceViewVM {
|
||||||
break;
|
break;
|
||||||
case EntityAction.markSent:
|
case EntityAction.markSent:
|
||||||
store.dispatch(MarkSentInvoiceRequest(
|
store.dispatch(MarkSentInvoiceRequest(
|
||||||
snackBarCompleter(
|
snackBarCompleter(context, localization.markedInvoiceAsSent),
|
||||||
context, localization.markedInvoiceAsSent),
|
|
||||||
invoice.id));
|
invoice.id));
|
||||||
break;
|
break;
|
||||||
case EntityAction.emailInvoice:
|
case EntityAction.emailInvoice:
|
||||||
store.dispatch(ShowEmailInvoice(
|
store.dispatch(ShowEmailInvoice(
|
||||||
completer: snackBarCompleter(
|
completer:
|
||||||
context, localization.emailedInvoice),
|
snackBarCompleter(context, localization.emailedInvoice),
|
||||||
invoice: invoice,
|
invoice: invoice,
|
||||||
context: context));
|
context: context));
|
||||||
break;
|
break;
|
||||||
case EntityAction.archive:
|
case EntityAction.archive:
|
||||||
store.dispatch(ArchiveInvoiceRequest(
|
store.dispatch(ArchiveInvoiceRequest(
|
||||||
popCompleter(
|
popCompleter(context, localization.archivedInvoice),
|
||||||
context, localization.archivedInvoice),
|
|
||||||
invoice.id));
|
invoice.id));
|
||||||
break;
|
break;
|
||||||
case EntityAction.delete:
|
case EntityAction.delete:
|
||||||
store.dispatch(DeleteInvoiceRequest(
|
store.dispatch(DeleteInvoiceRequest(
|
||||||
popCompleter(
|
popCompleter(context, localization.deletedInvoice),
|
||||||
context, localization.deletedInvoice),
|
|
||||||
invoice.id));
|
invoice.id));
|
||||||
break;
|
break;
|
||||||
case EntityAction.restore:
|
case EntityAction.restore:
|
||||||
store.dispatch(RestoreInvoiceRequest(
|
store.dispatch(RestoreInvoiceRequest(
|
||||||
snackBarCompleter(
|
snackBarCompleter(context, localization.restoredInvoice),
|
||||||
context, localization.restoredInvoice),
|
|
||||||
invoice.id));
|
invoice.id));
|
||||||
break;
|
break;
|
||||||
case EntityAction.clone:
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ class ProductListBuilder extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return StoreConnector<AppState, ProductListVM>(
|
return StoreConnector<AppState, ProductListVM>(
|
||||||
|
//distinct: true,
|
||||||
converter: ProductListVM.fromStore,
|
converter: ProductListVM.fromStore,
|
||||||
builder: (context, vm) {
|
builder: (context, vm) {
|
||||||
return ProductList(
|
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;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue