Skip to content

Commit cd1f922

Browse files
authored
fix(edit-currency): missing update store (#49)
1 parent f625c25 commit cd1f922

File tree

2 files changed

+64
-64
lines changed

2 files changed

+64
-64
lines changed

lib/src/pages/edit_currency_page.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ class _EditCurrencyPageState extends State<EditCurrencyPage> {
7070
);
7171
}
7272

73-
void _onContinue() {
73+
Future<void> _onContinue() async {
7474
final nav = Navigator.of(context);
75+
final shouldUpdateStore = _store.locale == '' || _store.symbol == '';
7576
if (_store.locale == '') _store.locale = getLocale(_curr);
7677
if (_store.symbol == '') _store.symbol = symbols[_curr];
78+
if (shouldUpdateStore) await _db.updateStore(_store);
7779
final args = InvoiceArgs(_store, widget.recipient);
7880
nav.pushReplacementNamed('/invoice', arguments: args);
7981
}

lib/src/pages/edit_item_page.dart

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -49,85 +49,83 @@ class _EditItemPageState extends State<EditItemPage> {
4949
final l10n = AppLocalizations.of(context)!;
5050
final disabledColor = Theme.of(context).disabledColor;
5151
final colors = Theme.of(context).colorScheme;
52+
final valid = _isValid(_formKey) && _nameCon.text.isNotEmpty;
5253

5354
return Scaffold(
5455
appBar: AppBar(title: Text(l10n.editItem)),
55-
body: Form(
56-
key: _formKey,
57-
child: SingleChildScrollView(
58-
child: Column(
59-
spacing: 16.0,
60-
children: [
61-
SizedBox.shrink(),
62-
Padding(
63-
padding: kPx,
64-
child: TextFormField(
65-
controller: _nameCon,
66-
keyboardType: TextInputType.name,
67-
decoration: InputDecoration(
68-
labelText: l10n.itemName,
69-
hintText: l10n.itemName,
56+
body: SingleChildScrollView(
57+
child: Container(
58+
margin: EdgeInsets.only(bottom: kToolbarHeight * 2),
59+
color: colors.surface,
60+
child: Form(
61+
key: _formKey,
62+
child: Column(
63+
spacing: 16.0,
64+
children: [
65+
SizedBox.shrink(),
66+
Padding(
67+
padding: kPx,
68+
child: TextFormField(
69+
controller: _nameCon,
70+
keyboardType: TextInputType.name,
71+
decoration: InputDecoration(
72+
labelText: l10n.itemName,
73+
hintText: l10n.itemName,
74+
),
75+
onChanged: (v) => setState(() {}),
7076
),
71-
onChanged: (v) => setState(() {}),
7277
),
73-
),
74-
Padding(
75-
padding: kPx,
76-
child: TextFormField(
77-
controller: _skuCon,
78-
decoration: InputDecoration(
79-
hintText: 'SKU',
80-
labelText: 'SKU',
78+
Padding(
79+
padding: kPx,
80+
child: TextFormField(
81+
controller: _skuCon,
82+
decoration: InputDecoration(
83+
hintText: 'SKU',
84+
labelText: 'SKU',
85+
),
86+
onChanged: (v) => setState(() {}),
8187
),
82-
onChanged: (v) => setState(() {}),
8388
),
84-
),
85-
Padding(
86-
padding: kPx,
87-
child: TextFormField(
88-
controller: _priceCon,
89-
decoration: InputDecoration(
90-
labelText: l10n.price,
91-
hintText: '5.0',
89+
Padding(
90+
padding: kPx,
91+
child: TextFormField(
92+
controller: _priceCon,
93+
decoration: InputDecoration(
94+
labelText: l10n.price,
95+
hintText: '5.0',
96+
),
97+
keyboardType: TextInputType.number,
98+
onChanged: (v) => setState(() {}),
9299
),
93-
keyboardType: TextInputType.number,
94-
onChanged: (v) => setState(() {}),
95100
),
96-
),
97-
Padding(
98-
padding: kPx,
99-
child: TextFormField(
100-
controller: _discCon,
101-
decoration: InputDecoration(
102-
labelText: l10n.discount,
103-
hintText: '0.0',
101+
Padding(
102+
padding: kPx,
103+
child: TextFormField(
104+
controller: _discCon,
105+
decoration: InputDecoration(
106+
labelText: l10n.discount,
107+
hintText: '0.0',
108+
),
109+
keyboardType: TextInputType.number,
110+
onChanged: (v) => setState(() {}),
104111
),
105-
keyboardType: TextInputType.number,
106-
onChanged: (v) => setState(() {}),
107112
),
108-
),
109-
SwitchListTile.adaptive(
110-
title: Text(l10n.usePercentage),
111-
value: _isPercent,
112-
onChanged: (v) => setState(() => _isPercent = v),
113-
),
114-
const SizedBox(height: kToolbarHeight * 2),
115-
],
113+
SwitchListTile.adaptive(
114+
title: Text(l10n.usePercentage),
115+
value: _isPercent,
116+
onChanged: (v) => setState(() => _isPercent = v),
117+
),
118+
const SizedBox.shrink(),
119+
],
120+
),
116121
),
117122
),
118123
),
119124
floatingActionButton: FloatingActionButton.extended(
120-
onPressed:
121-
_isValid(_formKey) && _nameCon.text.isNotEmpty
122-
? () => _onEditItem()
123-
: null,
125+
onPressed: valid ? () => _onEditItem() : null,
124126
disabledElevation: 0,
125-
backgroundColor:
126-
_nameCon.text.isNotEmpty ? colors.primaryContainer : disabledColor,
127-
foregroundColor:
128-
_nameCon.text.isNotEmpty
129-
? colors.onPrimaryContainer
130-
: disabledColor,
127+
backgroundColor: valid ? colors.primaryContainer : disabledColor,
128+
foregroundColor: valid ? colors.onPrimaryContainer : disabledColor,
131129
icon: Icon(Icons.done),
132130
label: Text(l10n.save),
133131
),

0 commit comments

Comments
 (0)