Flutter web

This commit is contained in:
Hillel Coren 2020-01-19 22:29:43 +02:00
parent 9bd7476a6b
commit 9e78bc7e41
11 changed files with 29 additions and 19 deletions

View File

@ -120,14 +120,17 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
BuiltList<HistoryRecord> get historyList => BuiltList<HistoryRecord> get historyList =>
prefState.companyPrefs[uiState.selectedCompanyIndex].historyList; prefState.companyPrefs[uiState.selectedCompanyIndex].historyList;
bool shouldSelectEntity(EntityType entityType) { bool shouldSelectEntity({EntityType entityType, bool hasRecords}) {
final entityList = getEntityList(entityType); final entityList = getEntityList(entityType);
final entityUIState = getUIState(entityType); final entityUIState = getUIState(entityType);
if (prefState.isMobile || entityList.isEmpty || uiState.isEditing) { if (prefState.isMobile || entityList.isEmpty || uiState.isEditing) {
return false; return false;
} }
if (!entityList.contains(entityUIState.selectedId)) { if (entityUIState.selectedId == null && !hasRecords) {
return false;
} else if (!entityList.contains(entityUIState.selectedId)) {
return true; return true;
} else if (historyList.isEmpty || } else if (historyList.isEmpty ||
!historyList.first.isEqualTo( !historyList.first.isEqualTo(

View File

@ -141,17 +141,18 @@ class MainScreen extends StatelessWidget {
onWillPop: () async { onWillPop: () async {
final state = store.state; final state = store.state;
final historyList = state.historyList; final historyList = state.historyList;
final editingOrSettings = final notViewingEntity = state.uiState.isEditing ||
state.uiState.isEditing || state.uiState.isInSettings; state.uiState.isInSettings ||
(historyList[0].entityType.toString() != state.uiState.mainRoute);
if (historyList.isEmpty || if (historyList.isEmpty ||
historyList.length == 1 && !editingOrSettings) { historyList.length == 1 && !notViewingEntity) {
return false; return false;
} }
final history = historyList[editingOrSettings ? 0 : 1]; final history = historyList[notViewingEntity ? 0 : 1];
if (!editingOrSettings) { if (!notViewingEntity) {
store.dispatch(PopLastHistory()); store.dispatch(PopLastHistory());
} }

View File

@ -78,7 +78,8 @@ class _ClientListState extends State<ClientList> {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
if (state.shouldSelectEntity(EntityType.client)) { if (state.shouldSelectEntity(
entityType: EntityType.client, hasRecords: clientList.isNotEmpty)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.client, entityType: EntityType.client,

View File

@ -29,7 +29,8 @@ class DocumentList extends StatelessWidget {
final isInMultiselect = listUIState.isInMultiselect(); final isInMultiselect = listUIState.isInMultiselect();
final documentList = viewModel.documentList; final documentList = viewModel.documentList;
if (state.shouldSelectEntity(EntityType.document)) { if (state.shouldSelectEntity(
entityType: EntityType.document, hasRecords: documentList.isNotEmpty)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.document, entityType: EntityType.document,

View File

@ -94,7 +94,8 @@ class _ExpenseListState extends State<ExpenseList> {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
if (state.shouldSelectEntity(EntityType.expense)) { if (state.shouldSelectEntity(
entityType: EntityType.expense, hasRecords: expenseList.isNotEmpty)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.expense, entityType: EntityType.expense,
@ -195,10 +196,9 @@ class _ExpenseListState extends State<ExpenseList> {
source: dataTableSource, source: dataTableSource,
header: DatatableHeader( header: DatatableHeader(
entityType: EntityType.expense, entityType: EntityType.expense,
onClearPressed: widget onClearPressed:
.viewModel.onClearEntityFilterPressed, widget.viewModel.onClearEntityFilterPressed,
), ),
), ),
)), )),
), ),

View File

@ -82,7 +82,8 @@ class _EntityListState extends State<InvoiceList> {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
if (state.shouldSelectEntity(EntityType.invoice)) { if (state.shouldSelectEntity(
entityType: EntityType.invoice, hasRecords: invoiceList.isNotEmpty)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.invoice, entityType: EntityType.invoice,

View File

@ -81,7 +81,8 @@ class _PaymentListState extends State<PaymentList> {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
if (state.shouldSelectEntity(EntityType.payment)) { if (state.shouldSelectEntity(
entityType: EntityType.payment, hasRecords: paymentList.isNotEmpty)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.payment, entityType: EntityType.payment,

View File

@ -78,7 +78,8 @@ class _ProductListState extends State<ProductList> {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
if (state.shouldSelectEntity(EntityType.product)) { if (state.shouldSelectEntity(
entityType: EntityType.product, hasRecords: productList.isNotEmpty)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.product, entityType: EntityType.product,

View File

@ -79,7 +79,7 @@ class _ProjectListState extends State<ProjectList> {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
if (state.shouldSelectEntity(EntityType.project)) { if (state.shouldSelectEntity(entityType: EntityType.project, hasRecords: projectList.isNotEmpty)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.project, entityType: EntityType.project,

View File

@ -72,7 +72,7 @@ class _TaskListState extends State<TaskList> {
final isInMultiselect = listUIState.isInMultiselect(); final isInMultiselect = listUIState.isInMultiselect();
final taskList = widget.viewModel.taskList; final taskList = widget.viewModel.taskList;
if (state.shouldSelectEntity(EntityType.task)) { if (state.shouldSelectEntity(entityType: EntityType.task, hasRecords: taskList.isNotEmpty)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.task, entityType: EntityType.task,

View File

@ -77,7 +77,8 @@ class _VendorListState extends State<VendorList> {
return HelpText(AppLocalization.of(context).noRecordsFound); return HelpText(AppLocalization.of(context).noRecordsFound);
} }
if (state.shouldSelectEntity(EntityType.vendor)) { if (state.shouldSelectEntity(
entityType: EntityType.vendor, hasRecords: vendorList.isNotEmpty)) {
viewEntityById( viewEntityById(
context: context, context: context,
entityType: EntityType.vendor, entityType: EntityType.vendor,