-
Notifications
You must be signed in to change notification settings - Fork 556
/
Copy pathstub_edit
103 lines (82 loc) · 2.87 KB
/
stub_edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import 'package:flutter/material.dart';
import 'package:invoiceninja_flutter/ui/app/edit_scaffold.dart';
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
import 'package:invoiceninja_flutter/ui/stub/edit/stub_edit_vm.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:invoiceninja_flutter/utils/completers.dart';
import 'package:invoiceninja_flutter/ui/app/scrollable_listview.dart';
class StubEdit extends StatefulWidget {
const StubEdit({
Key key,
@required this.viewModel,
}) : super(key: key);
final StubEditVM viewModel;
@override
_StubEditState createState() => _StubEditState();
}
class _StubEditState extends State<StubEdit> {
static final GlobalKey<FormState> _formKey = GlobalKey<FormState>(debugLabel: '_stubEdit');
final _debouncer = Debouncer();
// STARTER: controllers - do not remove comment
List<TextEditingController> _controllers = [];
@override
void didChangeDependencies() {
_controllers = [
// STARTER: array - do not remove comment
];
_controllers.forEach((controller) => controller.removeListener(_onChanged));
final stub = widget.viewModel.stub;
// STARTER: read value - do not remove comment
_controllers.forEach((controller) => controller.addListener(_onChanged));
super.didChangeDependencies();
}
@override
void dispose() {
_controllers.forEach((controller) {
controller.removeListener(_onChanged);
controller.dispose();
});
super.dispose();
}
void _onChanged() {
_debouncer.run(() {
final stub = widget.viewModel.stub.rebuild((b) => b
// STARTER: set value - do not remove comment
);
if (stub != widget.viewModel.stub) {
widget.viewModel.onChanged(stub);
}
});
}
@override
Widget build(BuildContext context) {
final viewModel = widget.viewModel;
final localization = AppLocalization.of(context);
final stub = viewModel.stub;
return EditScaffold(
title: stub.isNew ? localization.newStub : localization.editStub,
onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) {
final bool isValid = _formKey.currentState.validate();
if (!isValid) {
return;
}
viewModel.onSavePressed(context);
},
body:Form(
key: _formKey,
child: Builder(builder: (BuildContext context) {
return ScrollableListView(
children: <Widget>[
FormCard(
children: <Widget>[
// STARTER: widgets - do not remove comment
],
),
],
);
})
),
);
}
}