Starter...

This commit is contained in:
Hillel Coren 2020-03-02 21:20:12 +02:00
parent 5b0984ef18
commit 5aaf30f1f9
2 changed files with 238 additions and 202 deletions

View File

@ -2,17 +2,20 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/data/models/credit_model.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
import 'package:invoiceninja_flutter/ui/credit/credit_screen_vm.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/ui/credit/credit_list_vm.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/redux/credit/credit_actions.dart'; import 'package:invoiceninja_flutter/redux/credit/credit_actions.dart';
import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart'; import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart';
import 'package:invoiceninja_flutter/ui/app/forms/save_cancel_buttons.dart';
import 'package:invoiceninja_flutter/ui/app/list_scaffold.dart';
import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
import 'package:invoiceninja_flutter/ui/credit/credit_list_vm.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'credit_screen_vm.dart';
class CreditScreen extends StatelessWidget { class CreditScreen extends StatelessWidget {
const CreditScreen({ const CreditScreen({
@ -28,28 +31,29 @@ class CreditScreen extends StatelessWidget {
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 company = state.selectedCompany; final company = state.company;
final userCompany = state.userCompany;
final localization = AppLocalization.of(context); final localization = AppLocalization.of(context);
final listUIState = state.uiState.creditUIState.listUIState; final listUIState = state.uiState.creditUIState.listUIState;
final isInMultiselect = listUIState.isInMultiselect(); final isInMultiselect = listUIState.isInMultiselect();
return AppScaffold( return ListScaffold(
isChecked: isInMultiselect && isChecked: isInMultiselect &&
listUIState.selectedIds.length == viewModel.creditList.length, listUIState.selectedIds.length == viewModel.creditList.length,
showCheckbox: isInMultiselect, showCheckbox: isInMultiselect,
onHamburgerLongPress: () => store.dispatch(StartCreditMultiselect()),
onCheckboxChanged: (value) { onCheckboxChanged: (value) {
final credits = viewModel.creditList final credits = viewModel.creditList
.map<InvoiceEntity>((creditId) => viewModel.creditMap[creditId]) .map<InvoiceEntity>((creditId) => viewModel.creditMap[creditId])
.where((credit) => value != listUIState.isSelected(credit)) .where((credit) => value != listUIState.isSelected(credit.id))
.toList(); .toList();
viewModel.onEntityAction( handleCreditAction(context, credits, EntityAction.toggleMultiselect);
context, credits, EntityAction.toggleMultiselect);
}, },
appBarTitle: ListFilter( appBarTitle: ListFilter(
title: localization.credits title: localization.credits,
key: ValueKey(state.creditListState.filterClearedAt), key: ValueKey(state.creditListState.filterClearedAt),
entityType: EntityType.credit, filter: state.creditListState.filter,
onFilterChanged: (value) { onFilterChanged: (value) {
store.dispatch(FilterCredits(value)); store.dispatch(FilterCredits(value));
}, },
@ -57,7 +61,7 @@ class CreditScreen extends StatelessWidget {
appBarActions: [ appBarActions: [
if (!viewModel.isInMultiselect) if (!viewModel.isInMultiselect)
ListFilterButton( ListFilterButton(
entityType: EntityType.credit, filter: state.creditListState.filter,
onFilterPressed: (String value) { onFilterPressed: (String value) {
store.dispatch(FilterCredits(value)); store.dispatch(FilterCredits(value));
}, },
@ -74,10 +78,12 @@ class CreditScreen extends StatelessWidget {
.toList(); .toList();
await showEntityActionsDialog( await showEntityActionsDialog(
entities: credits, context: context, multiselect: true, entities: credits,
context: context,
multiselect: true,
completer: Completer<Null>() completer: Completer<Null>()
..future.then((_) => ..future.then<dynamic>(
store.dispatch(ClearCreditMultiselect())), (_) => store.dispatch(ClearCreditMultiselect())),
); );
}, },
onCancelPressed: (context) => onCancelPressed: (context) =>
@ -87,16 +93,12 @@ class CreditScreen extends StatelessWidget {
body: CreditListBuilder(), body: CreditListBuilder(),
bottomNavigationBar: AppBottomBar( bottomNavigationBar: AppBottomBar(
entityType: EntityType.credit, entityType: EntityType.credit,
onSelectedSortField: (value) => store.dispatch(SortCredits(value)), onSelectedSortField: (value) {
customValues1: company.getCustomFieldValues(CustomFieldType.credit1, store.dispatch(SortCredits(value));
excludeBlank: true), },
customValues2: company.getCustomFieldValues(CustomFieldType.credit2,
excludeBlank: true),
onSelectedCustom1: (value) =>
store.dispatch(FilterCreditsByCustom1(value)),
onSelectedCustom2: (value) =>
store.dispatch(FilterCreditsByCustom2(value)),
sortFields: [ sortFields: [
CreditFields.number,
CreditFields.amount,
CreditFields.updatedAt, CreditFields.updatedAt,
], ],
onSelectedState: (EntityState state, value) { onSelectedState: (EntityState state, value) {
@ -109,14 +111,30 @@ class CreditScreen extends StatelessWidget {
store.dispatch(StartCreditMultiselect()); store.dispatch(StartCreditMultiselect());
} }
}, },
customValues1: company.getCustomFieldValues(CustomFieldType.invoice1,
excludeBlank: true),
customValues2: company.getCustomFieldValues(CustomFieldType.invoice2,
excludeBlank: true),
customValues3: company.getCustomFieldValues(CustomFieldType.invoice3,
excludeBlank: true),
customValues4: company.getCustomFieldValues(CustomFieldType.invoice4,
excludeBlank: true),
onSelectedCustom1: (value) =>
store.dispatch(FilterCreditsByCustom1(value)),
onSelectedCustom2: (value) =>
store.dispatch(FilterCreditsByCustom2(value)),
onSelectedCustom3: (value) =>
store.dispatch(FilterCreditsByCustom3(value)),
onSelectedCustom4: (value) =>
store.dispatch(FilterCreditsByCustom4(value)),
), ),
floatingActionButton: user.canCreate(EntityType.credit) floatingActionButton: userCompany.canCreate(EntityType.credit)
? FloatingActionButton( ? FloatingActionButton(
heroTag: 'credit_fab', heroTag: 'credit_fab',
backgroundColor: Theme.of(context).primaryColorDark, backgroundColor: Theme.of(context).primaryColorDark,
onPressed: () { onPressed: () {
store.dispatch( createEntityByType(
EditCredit(credit: InvoiceEntity(), context: context)); context: context, entityType: EntityType.credit);
}, },
child: Icon( child: Icon(
Icons.add, Icons.add,

View File

@ -2,17 +2,20 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/data/models/stub_model.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
import 'package:invoiceninja_flutter/ui/stub/stub_screen_vm.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/ui/stub/stub_list_vm.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/redux/stub/stub_actions.dart'; import 'package:invoiceninja_flutter/redux/stub/stub_actions.dart';
import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart'; import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart';
import 'package:invoiceninja_flutter/ui/app/forms/save_cancel_buttons.dart';
import 'package:invoiceninja_flutter/ui/app/list_scaffold.dart';
import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
import 'package:invoiceninja_flutter/ui/stub/stub_list_vm.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'stub_screen_vm.dart';
class StubScreen extends StatelessWidget { class StubScreen extends StatelessWidget {
const StubScreen({ const StubScreen({
@ -28,28 +31,29 @@ class StubScreen extends StatelessWidget {
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 company = state.selectedCompany; final company = state.company;
final userCompany = state.userCompany;
final localization = AppLocalization.of(context); final localization = AppLocalization.of(context);
final listUIState = state.uiState.stubUIState.listUIState; final listUIState = state.uiState.stubUIState.listUIState;
final isInMultiselect = listUIState.isInMultiselect(); final isInMultiselect = listUIState.isInMultiselect();
return AppScaffold( return ListScaffold(
isChecked: isInMultiselect && isChecked: isInMultiselect &&
listUIState.selectedIds.length == viewModel.stubList.length, listUIState.selectedIds.length == viewModel.stubList.length,
showCheckbox: isInMultiselect, showCheckbox: isInMultiselect,
onHamburgerLongPress: () => store.dispatch(StartStubMultiselect()),
onCheckboxChanged: (value) { onCheckboxChanged: (value) {
final stubs = viewModel.stubList final stubs = viewModel.stubList
.map<StubEntity>((stubId) => viewModel.stubMap[stubId]) .map<StubEntity>((stubId) => viewModel.stubMap[stubId])
.where((stub) => value != listUIState.isSelected(stub)) .where((stub) => value != listUIState.isSelected(stub.id))
.toList(); .toList();
viewModel.onEntityAction( handleStubAction(context, stubs, EntityAction.toggleMultiselect);
context, stubs, EntityAction.toggleMultiselect);
}, },
appBarTitle: ListFilter( appBarTitle: ListFilter(
title: localization.stubs title: localization.stubs,
key: ValueKey(state.stubListState.filterClearedAt), key: ValueKey(state.stubListState.filterClearedAt),
entityType: EntityType.stub, filter: state.stubListState.filter,
onFilterChanged: (value) { onFilterChanged: (value) {
store.dispatch(FilterStubs(value)); store.dispatch(FilterStubs(value));
}, },
@ -57,7 +61,7 @@ class StubScreen extends StatelessWidget {
appBarActions: [ appBarActions: [
if (!viewModel.isInMultiselect) if (!viewModel.isInMultiselect)
ListFilterButton( ListFilterButton(
entityType: EntityType.stub, filter: state.stubListState.filter,
onFilterPressed: (String value) { onFilterPressed: (String value) {
store.dispatch(FilterStubs(value)); store.dispatch(FilterStubs(value));
}, },
@ -74,10 +78,12 @@ class StubScreen extends StatelessWidget {
.toList(); .toList();
await showEntityActionsDialog( await showEntityActionsDialog(
entities: stubs, context: context, multiselect: true, entities: stubs,
context: context,
multiselect: true,
completer: Completer<Null>() completer: Completer<Null>()
..future.then((_) => ..future.then<dynamic>(
store.dispatch(ClearStubMultiselect())), (_) => store.dispatch(ClearStubMultiselect())),
); );
}, },
onCancelPressed: (context) => onCancelPressed: (context) =>
@ -87,16 +93,12 @@ class StubScreen extends StatelessWidget {
body: StubListBuilder(), body: StubListBuilder(),
bottomNavigationBar: AppBottomBar( bottomNavigationBar: AppBottomBar(
entityType: EntityType.stub, entityType: EntityType.stub,
onSelectedSortField: (value) => store.dispatch(SortStubs(value)), onSelectedSortField: (value) {
customValues1: company.getCustomFieldValues(CustomFieldType.stub1, store.dispatch(SortStubs(value));
excludeBlank: true), },
customValues2: company.getCustomFieldValues(CustomFieldType.stub2,
excludeBlank: true),
onSelectedCustom1: (value) =>
store.dispatch(FilterStubsByCustom1(value)),
onSelectedCustom2: (value) =>
store.dispatch(FilterStubsByCustom2(value)),
sortFields: [ sortFields: [
StubFields.name,
StubFields.balance,
StubFields.updatedAt, StubFields.updatedAt,
], ],
onSelectedState: (EntityState state, value) { onSelectedState: (EntityState state, value) {
@ -109,14 +111,30 @@ class StubScreen extends StatelessWidget {
store.dispatch(StartStubMultiselect()); store.dispatch(StartStubMultiselect());
} }
}, },
customValues1: company.getCustomFieldValues(CustomFieldType.stub1,
excludeBlank: true),
customValues2: company.getCustomFieldValues(CustomFieldType.stub2,
excludeBlank: true),
customValues3: company.getCustomFieldValues(CustomFieldType.stub3,
excludeBlank: true),
customValues4: company.getCustomFieldValues(CustomFieldType.stub4,
excludeBlank: true),
onSelectedCustom1: (value) =>
store.dispatch(FilterStubsByCustom1(value)),
onSelectedCustom2: (value) =>
store.dispatch(FilterStubsByCustom2(value)),
onSelectedCustom3: (value) =>
store.dispatch(FilterStubsByCustom3(value)),
onSelectedCustom4: (value) =>
store.dispatch(FilterStubsByCustom4(value)),
), ),
floatingActionButton: user.canCreate(EntityType.stub) floatingActionButton: userCompany.canCreate(EntityType.stub)
? FloatingActionButton( ? FloatingActionButton(
heroTag: 'stub_fab', heroTag: 'stub_fab',
backgroundColor: Theme.of(context).primaryColorDark, backgroundColor: Theme.of(context).primaryColorDark,
onPressed: () { onPressed: () {
store.dispatch( createEntityByType(
EditStub(stub: StubEntity(), context: context)); context: context, entityType: EntityType.stub);
}, },
child: Icon( child: Icon(
Icons.add, Icons.add,