Flutter web

This commit is contained in:
Hillel Coren 2020-01-19 21:55:49 +02:00
parent e9cdf8eebc
commit 9bd7476a6b
15 changed files with 72 additions and 51 deletions

View File

@ -301,21 +301,20 @@ void viewEntitiesByType({
} }
} }
void viewEntityById( void viewEntityById({
{BuildContext context, BuildContext context,
String entityId, String entityId,
EntityType entityType, EntityType entityType,
bool force = false, bool force = false,
bool showError = true}) { }) {
final store = StoreProvider.of<AppState>(context); final store = StoreProvider.of<AppState>(context);
final navigator = Navigator.of(context); final navigator = Navigator.of(context);
if (!store.state.getEntityMap(entityType).containsKey(entityId)) { if (entityId != null &&
if (showError) { !store.state.getEntityMap(entityType).containsKey(entityId)) {
showErrorDialog( showErrorDialog(
context: context, context: context,
message: AppLocalization.of(context).failedToFindRecord); message: AppLocalization.of(context).failedToFindRecord);
}
return; return;
} }

View File

@ -444,7 +444,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
//return 'Payment: ${uiState.paymentUIState.editing.paymentables}'; //return 'Payment: ${uiState.paymentUIState.editing.paymentables}';
//return 'isAuthenticated: ${authState.isAuthenticated}'; //return 'isAuthenticated: ${authState.isAuthenticated}';
//return 'MultiSelect: ${productListState.isInMultiselect()} SelectedIds: ${productListState.selectedIds}'; //return 'MultiSelect: ${productListState.isInMultiselect()} SelectedIds: ${productListState.selectedIds}';
return 'History: $historyList'; //return 'History: $historyList';
return 'Route: ${uiState.currentRoute} Prev: ${uiState.previousRoute}'; return 'Route: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
} }
} }

View File

@ -391,7 +391,7 @@ Reducer<BuiltList<HistoryRecord>> historyReducer = combineReducers([
BuiltList<HistoryRecord> _addToHistory( BuiltList<HistoryRecord> _addToHistory(
BuiltList<HistoryRecord> list, HistoryRecord record) { BuiltList<HistoryRecord> list, HistoryRecord record) {
// don't track new records // don't track new records
if (record.id.startsWith('-')) { if (record.id == null || record.id.startsWith('-')) {
return list; return list;
} }

View File

@ -183,6 +183,7 @@ abstract class HistoryRecord
HistoryRecord._(); HistoryRecord._();
@nullable
String get id; String get id;
EntityType get entityType; EntityType get entityType;

View File

@ -363,8 +363,6 @@ class _$HistoryRecordSerializer implements StructuredSerializer<HistoryRecord> {
Iterable<Object> serialize(Serializers serializers, HistoryRecord object, Iterable<Object> serialize(Serializers serializers, HistoryRecord object,
{FullType specifiedType = FullType.unspecified}) { {FullType specifiedType = FullType.unspecified}) {
final result = <Object>[ final result = <Object>[
'id',
serializers.serialize(object.id, specifiedType: const FullType(String)),
'entityType', 'entityType',
serializers.serialize(object.entityType, serializers.serialize(object.entityType,
specifiedType: const FullType(EntityType)), specifiedType: const FullType(EntityType)),
@ -372,7 +370,12 @@ class _$HistoryRecordSerializer implements StructuredSerializer<HistoryRecord> {
serializers.serialize(object.timestamp, serializers.serialize(object.timestamp,
specifiedType: const FullType(int)), specifiedType: const FullType(int)),
]; ];
if (object.id != null) {
result
..add('id')
..add(serializers.serialize(object.id,
specifiedType: const FullType(String)));
}
return result; return result;
} }
@ -833,9 +836,6 @@ class _$HistoryRecord extends HistoryRecord {
(new HistoryRecordBuilder()..update(updates)).build(); (new HistoryRecordBuilder()..update(updates)).build();
_$HistoryRecord._({this.id, this.entityType, this.timestamp}) : super._() { _$HistoryRecord._({this.id, this.entityType, this.timestamp}) : super._() {
if (id == null) {
throw new BuiltValueNullFieldError('HistoryRecord', 'id');
}
if (entityType == null) { if (entityType == null) {
throw new BuiltValueNullFieldError('HistoryRecord', 'entityType'); throw new BuiltValueNullFieldError('HistoryRecord', 'entityType');
} }

View File

@ -156,11 +156,10 @@ class MainScreen extends StatelessWidget {
} }
viewEntityById( viewEntityById(
entityType: history.entityType, entityType: history.entityType,
entityId: history.id, entityId: history.id,
context: context, context: context,
showError: );
false); // in case the history record has since been deleted
return false; return false;
}, },

View File

@ -74,15 +74,16 @@ class _ClientListState extends State<ClientList> {
if (!viewModel.isLoaded) { if (!viewModel.isLoaded) {
return viewModel.isLoading ? LoadingIndicator() : SizedBox(); return viewModel.isLoading ? LoadingIndicator() : SizedBox();
} else if (clientList.isEmpty) { } else if (viewModel.clientMap.isEmpty) {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
if (state.shouldSelectEntity(EntityType.client)) { if (state.shouldSelectEntity(EntityType.client)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.client, entityType: EntityType.client,
entityId: clientList.first); entityId: clientList.isEmpty ? null : clientList.first,
);
} }
final listOrTable = () { final listOrTable = () {

View File

@ -33,7 +33,7 @@ class DocumentList extends StatelessWidget {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.document, entityType: EntityType.document,
entityId: documentList.first); entityId: documentList.isEmpty ? null : documentList.first);
} }
/* /*
@ -51,7 +51,7 @@ class DocumentList extends StatelessWidget {
? LoadingIndicator() ? LoadingIndicator()
: RefreshIndicator( : RefreshIndicator(
onRefresh: () => viewModel.onRefreshed(context), onRefresh: () => viewModel.onRefreshed(context),
child: viewModel.documentList.isEmpty child: viewModel.documentMap.isEmpty
? HelpText(AppLocalization.of(context).noRecordsFound) ? HelpText(AppLocalization.of(context).noRecordsFound)
: ListView.separated( : ListView.separated(
shrinkWrap: true, shrinkWrap: true,

View File

@ -85,13 +85,20 @@ class _ExpenseListState extends State<ExpenseList> {
final store = StoreProvider.of<AppState>(context); final store = StoreProvider.of<AppState>(context);
final listUIState = store.state.uiState.expenseUIState.listUIState; final listUIState = store.state.uiState.expenseUIState.listUIState;
final isInMultiselect = listUIState.isInMultiselect(); final isInMultiselect = listUIState.isInMultiselect();
final expenseList = widget.viewModel.expenseList; final viewModel = widget.viewModel;
final expenseList = viewModel.expenseList;
if (!viewModel.isLoaded) {
return viewModel.isLoading ? LoadingIndicator() : SizedBox();
} else if (viewModel.expenseMap.isEmpty) {
return HelpText(AppLocalization.of(context).noRecordsFound);
}
if (state.shouldSelectEntity(EntityType.expense)) { if (state.shouldSelectEntity(EntityType.expense)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.expense, entityType: EntityType.expense,
entityId: expenseList.first); entityId: expenseList.isEmpty ? null : expenseList.first);
} }
widgets.add(Expanded( widgets.add(Expanded(
@ -99,7 +106,7 @@ class _ExpenseListState extends State<ExpenseList> {
? LoadingIndicator() ? LoadingIndicator()
: RefreshIndicator( : RefreshIndicator(
onRefresh: () => widget.viewModel.onRefreshed(context), onRefresh: () => widget.viewModel.onRefreshed(context),
child: widget.viewModel.expenseList.isEmpty child: widget.viewModel.expenseMap.isEmpty
? HelpText(AppLocalization.of(context).noRecordsFound) ? HelpText(AppLocalization.of(context).noRecordsFound)
: state.prefState.moduleLayout == ModuleLayout.list : state.prefState.moduleLayout == ModuleLayout.list
? ListView.separated( ? ListView.separated(

View File

@ -78,15 +78,16 @@ class _EntityListState extends State<InvoiceList> {
if (!viewModel.isLoaded) { if (!viewModel.isLoaded) {
return viewModel.isLoading ? LoadingIndicator() : SizedBox(); return viewModel.isLoading ? LoadingIndicator() : SizedBox();
} else if (invoiceList.isEmpty) { } else if (viewModel.invoiceMap.isEmpty) {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
if (state.shouldSelectEntity(EntityType.invoice)) { if (state.shouldSelectEntity(EntityType.invoice)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.invoice, entityType: EntityType.invoice,
entityId: invoiceList.first); entityId: invoiceList.isEmpty ? null : invoiceList.first,
);
} }
final listOrTable = () { final listOrTable = () {

View File

@ -77,7 +77,7 @@ class _PaymentListState extends State<PaymentList> {
if (!viewModel.isLoaded) { if (!viewModel.isLoaded) {
return viewModel.isLoading ? LoadingIndicator() : SizedBox(); return viewModel.isLoading ? LoadingIndicator() : SizedBox();
} else if (paymentList.isEmpty) { } else if (viewModel.paymentMap.isEmpty) {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
@ -85,7 +85,7 @@ class _PaymentListState extends State<PaymentList> {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.payment, entityType: EntityType.payment,
entityId: paymentList.first); entityId: paymentList.isEmpty ? null : paymentList.first);
} }
final listOrTable = () { final listOrTable = () {

View File

@ -74,7 +74,7 @@ class _ProductListState extends State<ProductList> {
if (!viewModel.isLoaded) { if (!viewModel.isLoaded) {
return viewModel.isLoading ? LoadingIndicator() : SizedBox(); return viewModel.isLoading ? LoadingIndicator() : SizedBox();
} else if (productList.isEmpty) { } else if (viewModel.productMap.isEmpty) {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
@ -82,7 +82,7 @@ class _ProductListState extends State<ProductList> {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.product, entityType: EntityType.product,
entityId: productList.first); entityId: productList.isEmpty ? null : productList.first);
} }
final listOrTable = () { final listOrTable = () {
@ -153,7 +153,6 @@ class _ProductListState extends State<ProductList> {
header: DatatableHeader( header: DatatableHeader(
entityType: EntityType.product, entityType: EntityType.product,
), ),
), ),
)); ));
} }

View File

@ -68,15 +68,22 @@ class _ProjectListState extends State<ProjectList> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final store = StoreProvider.of<AppState>(context); final store = StoreProvider.of<AppState>(context);
final state = store.state; final state = store.state;
final viewModel = widget.viewModel;
final listState = widget.viewModel.listState; final listState = widget.viewModel.listState;
final isInMultiselect = listState.isInMultiselect(); final isInMultiselect = listState.isInMultiselect();
final projectList = widget.viewModel.projectList; final projectList = widget.viewModel.projectList;
if (!viewModel.isLoaded) {
return viewModel.isLoading ? LoadingIndicator() : SizedBox();
} else if (viewModel.projectMap.isEmpty) {
return HelpText(AppLocalization.of(context).noRecordsFound);
}
if (state.shouldSelectEntity(EntityType.project)) { if (state.shouldSelectEntity(EntityType.project)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.project, entityType: EntityType.project,
entityId: projectList.first); entityId: projectList.isEmpty ? null : projectList.first);
} }
return Column( return Column(
@ -93,7 +100,7 @@ class _ProjectListState extends State<ProjectList> {
? LoadingIndicator() ? LoadingIndicator()
: RefreshIndicator( : RefreshIndicator(
onRefresh: () => widget.viewModel.onRefreshed(context), onRefresh: () => widget.viewModel.onRefreshed(context),
child: widget.viewModel.projectList.isEmpty child: widget.viewModel.projectMap.isEmpty
? HelpText(AppLocalization.of(context).noRecordsFound) ? HelpText(AppLocalization.of(context).noRecordsFound)
: state.prefState.moduleLayout == ModuleLayout.list : state.prefState.moduleLayout == ModuleLayout.list
? ListView.separated( ? ListView.separated(

View File

@ -76,7 +76,7 @@ class _TaskListState extends State<TaskList> {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.task, entityType: EntityType.task,
entityId: taskList.first); entityId: taskList.isEmpty ? null : taskList.first);
} }
return Column( return Column(
@ -93,7 +93,7 @@ class _TaskListState extends State<TaskList> {
? LoadingIndicator() ? LoadingIndicator()
: RefreshIndicator( : RefreshIndicator(
onRefresh: () => widget.viewModel.onRefreshed(context), onRefresh: () => widget.viewModel.onRefreshed(context),
child: widget.viewModel.taskList.isEmpty child: widget.viewModel.taskMap.isEmpty
? HelpText(AppLocalization.of(context).noRecordsFound) ? HelpText(AppLocalization.of(context).noRecordsFound)
: state.prefState.moduleLayout == ModuleLayout.list : state.prefState.moduleLayout == ModuleLayout.list
? ListView.separated( ? ListView.separated(

View File

@ -66,15 +66,22 @@ class _VendorListState extends State<VendorList> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final store = StoreProvider.of<AppState>(context); final store = StoreProvider.of<AppState>(context);
final state = store.state; final state = store.state;
final listUIState = store.state.uiState.vendorUIState.listUIState; final viewModel = widget.viewModel;
final listUIState = state.uiState.vendorUIState.listUIState;
final isInMultiselect = listUIState.isInMultiselect(); final isInMultiselect = listUIState.isInMultiselect();
final vendorList = widget.viewModel.vendorList; final vendorList = viewModel.vendorList;
if (!viewModel.isLoaded) {
return viewModel.isLoading ? LoadingIndicator() : SizedBox();
} else if (viewModel.vendorMap.isEmpty) {
return HelpText(AppLocalization.of(context).noRecordsFound);
}
if (state.shouldSelectEntity(EntityType.vendor)) { if (state.shouldSelectEntity(EntityType.vendor)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.vendor, entityType: EntityType.vendor,
entityId: vendorList.first); entityId: vendorList.isEmpty ? null : vendorList.first);
} }
return Column( return Column(
@ -84,7 +91,7 @@ class _VendorListState extends State<VendorList> {
? LoadingIndicator() ? LoadingIndicator()
: RefreshIndicator( : RefreshIndicator(
onRefresh: () => widget.viewModel.onRefreshed(context), onRefresh: () => widget.viewModel.onRefreshed(context),
child: widget.viewModel.vendorList.isEmpty child: widget.viewModel.vendorMap.isEmpty
? HelpText(AppLocalization.of(context).noRecordsFound) ? HelpText(AppLocalization.of(context).noRecordsFound)
: state.prefState.moduleLayout == ModuleLayout.list : state.prefState.moduleLayout == ModuleLayout.list
? ListView.separated( ? ListView.separated(