This commit is contained in:
Hillel Coren 2018-12-13 19:24:18 +02:00
parent 0ffbe4d405
commit b74bfcdae8
2 changed files with 51 additions and 2 deletions

View File

@ -1,5 +1,9 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:invoiceninja_flutter/data/models/entities.dart';
import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/redux/client/client_selectors.dart';
import 'package:invoiceninja_flutter/ui/app/entity_dropdown.dart';
import 'package:invoiceninja_flutter/ui/app/form_card.dart'; import 'package:invoiceninja_flutter/ui/app/form_card.dart';
import 'package:invoiceninja_flutter/ui/project/edit/project_edit_vm.dart'; import 'package:invoiceninja_flutter/ui/project/edit/project_edit_vm.dart';
import 'package:invoiceninja_flutter/ui/app/buttons/refresh_icon_button.dart'; import 'package:invoiceninja_flutter/ui/app/buttons/refresh_icon_button.dart';
@ -61,6 +65,7 @@ class _ProjectEditState extends State<ProjectEdit> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final viewModel = widget.viewModel; final viewModel = widget.viewModel;
final localization = AppLocalization.of(context); final localization = AppLocalization.of(context);
final state = viewModel.state;
final project = viewModel.project; final project = viewModel.project;
return WillPopScope( return WillPopScope(
@ -95,7 +100,26 @@ class _ProjectEditState extends State<ProjectEdit> {
children: <Widget>[ children: <Widget>[
FormCard( FormCard(
children: <Widget>[ children: <Widget>[
// STARTER: widgets - do not remove comment EntityDropdown(
entityType: EntityType.client,
labelText: localization.client,
initialValue: (state.clientState.map[project.clientId] ??
ClientEntity())
.displayName,
entityMap: state.clientState.map,
entityList: memoizedDropdownClientList(
state.clientState.map, state.clientState.list),
validator: (String val) => val.trim().isEmpty
? AppLocalization.of(context).pleaseSelectAClient
: null,
onSelected: (clientId) {
viewModel.onChanged(
project.rebuild((b) => b..clientId = clientId));
},
onAddPressed: (completer) {
viewModel.onAddClientPressed(context, completer);
},
),
], ],
), ),
], ],

View File

@ -2,8 +2,13 @@ import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
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/client_model.dart';
import 'package:invoiceninja_flutter/data/models/entities.dart';
import 'package:invoiceninja_flutter/redux/client/client_actions.dart';
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
import 'package:invoiceninja_flutter/ui/app/snackbar_row.dart';
import 'package:invoiceninja_flutter/ui/project/project_screen.dart'; import 'package:invoiceninja_flutter/ui/project/project_screen.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:redux/redux.dart'; import 'package:redux/redux.dart';
import 'package:invoiceninja_flutter/redux/project/project_actions.dart'; import 'package:invoiceninja_flutter/redux/project/project_actions.dart';
import 'package:invoiceninja_flutter/data/models/project_model.dart'; import 'package:invoiceninja_flutter/data/models/project_model.dart';
@ -32,8 +37,10 @@ class ProjectEditScreen extends StatelessWidget {
class ProjectEditVM { class ProjectEditVM {
ProjectEditVM({ ProjectEditVM({
@required this.state,
@required this.project, @required this.project,
@required this.onChanged, @required this.onChanged,
@required this.onAddClientPressed,
@required this.isSaving, @required this.isSaving,
@required this.origProject, @required this.origProject,
@required this.onSavePressed, @required this.onSavePressed,
@ -49,6 +56,7 @@ class ProjectEditVM {
isLoading: state.isLoading, isLoading: state.isLoading,
isSaving: state.isSaving, isSaving: state.isSaving,
project: project, project: project,
state: state,
origProject: state.projectState.map[project.id], origProject: state.projectState.map[project.id],
onChanged: (ProjectEntity project) { onChanged: (ProjectEntity project) {
store.dispatch(UpdateProject(project)); store.dispatch(UpdateProject(project));
@ -56,9 +64,23 @@ class ProjectEditVM {
onBackPressed: () { onBackPressed: () {
store.dispatch(UpdateCurrentRoute(ProjectScreen.route)); store.dispatch(UpdateCurrentRoute(ProjectScreen.route));
}, },
onAddClientPressed: (context, completer) {
store.dispatch(EditClient(
client: ClientEntity(),
context: context,
completer: completer,
trackRoute: false));
completer.future.then((SelectableEntity client) {
Scaffold.of(context).showSnackBar(SnackBar(
content: SnackBarRow(
message: AppLocalization.of(context).createdClient,
)));
});
},
onSavePressed: (BuildContext context) { onSavePressed: (BuildContext context) {
final Completer<Null> completer = new Completer<Null>(); final Completer<Null> completer = new Completer<Null>();
store.dispatch(SaveProjectRequest(completer: completer, project: project)); store.dispatch(
SaveProjectRequest(completer: completer, project: project));
return completer.future.then((_) { return completer.future.then((_) {
/* /*
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
@ -81,4 +103,7 @@ class ProjectEditVM {
final ProjectEntity origProject; final ProjectEntity origProject;
final Function onBackPressed; final Function onBackPressed;
final bool isLoading; final bool isLoading;
final AppState state;
final Function(BuildContext context, Completer<SelectableEntity> completer)
onAddClientPressed;
} }