@@ -22,13 +22,13 @@ class HomePage extends StatefulWidget {
22
22
}
23
23
24
24
class _HomePageState extends State <HomePage > {
25
+ TemperatureUnit _temperatureUnit = form.defaultTemperatureUnit;
25
26
double _inoculation = 0 ;
26
27
double _bulkRise = 0 ;
27
28
double _flour = 0 ;
28
29
double _water = 0 ;
29
30
double _levain = 0 ;
30
31
double _salt = 0 ;
31
- TemperatureUnit ? _temperatureUnit;
32
32
33
33
final totalWeightController = TextEditingController ();
34
34
final hydrationController = TextEditingController ();
@@ -45,8 +45,8 @@ class _HomePageState extends State<HomePage> {
45
45
void _updateFermentationValues () {
46
46
final temperature = _parseValue (temperatureController);
47
47
48
- _inoculation = getInoculationValue (temperature, _temperatureUnit! );
49
- _bulkRise = getBulkRiseValue (temperature, _temperatureUnit! );
48
+ _inoculation = getInoculationValue (temperature, _temperatureUnit);
49
+ _bulkRise = getBulkRiseValue (temperature, _temperatureUnit);
50
50
}
51
51
52
52
void _updateFermentationState () {
@@ -79,7 +79,7 @@ class _HomePageState extends State<HomePage> {
79
79
.firstWhere ((element) => element.value.unit == selection)
80
80
.key;
81
81
temperatureController.text = convertTemperatureUnit (
82
- _parseValue (temperatureController), _temperatureUnit! )
82
+ _parseValue (temperatureController), _temperatureUnit)
83
83
.toStringAsFixed (1 )
84
84
.replaceFirst ('.0' , '' );
85
85
_storeTemperatureUnit ();
@@ -117,14 +117,13 @@ class _HomePageState extends State<HomePage> {
117
117
saltController.text =
118
118
await getInitialOrDefaultValue (saltLevelKey, form.defaultSaltLevel);
119
119
120
- _updateFermentationValues ();
121
- _updateIngredientsValues ();
120
+ _updateFermentationState ();
121
+ _updateIngredientsState ();
122
122
}
123
123
124
124
@override
125
125
initState () {
126
126
_loadInitialValues ();
127
-
128
127
super .initState ();
129
128
}
130
129
@@ -203,37 +202,40 @@ class _HomePageState extends State<HomePage> {
203
202
fontSize:
204
203
Theme .of (context).textTheme.bodyLarge! .fontSize,
205
204
color: Colors .grey.shade800)),
206
- if (_temperatureUnit != null )
207
- UnitChoice (
208
- a11yLabel: locale.a11yTemperatureUnitChoiceLabel,
209
- unitList: temperatureUnitMap.values
210
- .map ((element) => UnitSingleChoiceDescriptor (
211
- value: element.unit,
212
- tooltip: element.description))
213
- .toList (),
214
- initialUnitValue:
215
- temperatureUnitMap[_temperatureUnit]! .unit,
216
- onSelectionChanged: _updateTemperatureUnit),
205
+ UnitChoice (
206
+ a11yLabel: locale.a11yTemperatureUnitChoiceLabel,
207
+ unitList: temperatureUnitMap.values
208
+ .map ((element) => UnitSingleChoiceDescriptor (
209
+ value: element.unit,
210
+ tooltip: element.description))
211
+ .toList (),
212
+ getInitialUnitValue: () async {
213
+ return await getInitialOrDefaultValue (
214
+ temperatureUnitKey,
215
+ form.defaultTemperatureUnitValue);
216
+ },
217
+ onSelectionChanged: (selection) {
218
+ _updateTemperatureUnit (selection);
219
+ _storeTemperatureValue ();
220
+ }),
221
+ ],
222
+ ),
223
+ Row (
224
+ children: < TextFieldWithAffixes > [
225
+ TextFieldWithAffixes (
226
+ paddingTop: 10 ,
227
+ controller: temperatureController,
228
+ prefixText: locale.inputPrefixTemperature,
229
+ suffixText: temperatureUnitMap[_temperatureUnit]! .unit,
230
+ tooltip: locale.inputTooltipTemperature,
231
+ maxValue: form.maxValueTemperatureMap[_temperatureUnit]! ,
232
+ onChangedCallbacks: [
233
+ _updateFermentationState,
234
+ _storeTemperatureValue
235
+ ],
236
+ ),
217
237
],
218
238
),
219
- if (_temperatureUnit != null )
220
- Row (
221
- children: < TextFieldWithAffixes > [
222
- TextFieldWithAffixes (
223
- paddingTop: 10 ,
224
- controller: temperatureController,
225
- prefixText: locale.inputPrefixTemperature,
226
- suffixText: temperatureUnitMap[_temperatureUnit]! .unit,
227
- tooltip: locale.inputTooltipTemperature,
228
- maxValue:
229
- form.maxValueTemperatureMap[_temperatureUnit]! ,
230
- onChangedCallbacks: [
231
- _updateFermentationState,
232
- _storeTemperatureValue
233
- ],
234
- ),
235
- ],
236
- ),
237
239
Row (
238
240
children: < TextFieldWithAffixes > [
239
241
TextFieldWithAffixes (
@@ -252,11 +254,11 @@ class _HomePageState extends State<HomePage> {
252
254
Row (
253
255
children: < TextFieldWithAffixes > [
254
256
TextFieldWithAffixes (
255
- controller: hydrationController,
256
- prefixText: locale.inputPrefixHydration,
257
- suffixText: locale.unitPercent,
258
- tooltip: locale.inputTooltipHydration,
259
- maxValue: form.maxValueHydration,
257
+ controller: hydrationController,
258
+ prefixText: locale.inputPrefixHydration,
259
+ suffixText: locale.unitPercent,
260
+ tooltip: locale.inputTooltipHydration,
261
+ maxValue: form.maxValueHydration,
260
262
onChangedCallbacks: [
261
263
_updateIngredientsState,
262
264
_storeHydrationValue
0 commit comments