5
5
import 'package:flutter/cupertino.dart' ;
6
6
import 'package:go_router/go_router.dart' ;
7
7
import 'package:provider/provider.dart' ;
8
- import 'package:veggieseasons/data/app_state.dart' ;
9
- import 'package:veggieseasons/data/preferences.dart' ;
10
- import 'package:veggieseasons/data/veggie.dart' ;
11
- import 'package:veggieseasons/styles.dart' ;
12
- import 'package:veggieseasons/widgets/close_button.dart' ;
13
- import 'package:veggieseasons/widgets/trivia.dart' ;
8
+ import '../data/app_state.dart' ;
9
+ import '../data/preferences.dart' ;
10
+ import '../data/veggie.dart' ;
11
+ import '../styles.dart' ;
12
+ import '../widgets/detail_buttons.dart' ;
14
13
15
14
class ServingInfoChart extends StatelessWidget {
16
15
const ServingInfoChart (this .veggie, this .prefs, {super .key});
@@ -44,23 +43,7 @@ class ServingInfoChart extends StatelessWidget {
44
43
return Column (
45
44
children: [
46
45
const SizedBox (height: 16 ),
47
- Align (
48
- alignment: Alignment .centerLeft,
49
- child: Padding (
50
- padding: const EdgeInsets .only (
51
- left: 9 ,
52
- bottom: 4 ,
53
- ),
54
- child: Text (
55
- 'Serving info' ,
56
- style: CupertinoTheme .of (context).textTheme.textStyle,
57
- ),
58
- ),
59
- ),
60
46
Container (
61
- decoration: BoxDecoration (
62
- border: Border .all (color: Styles .servingInfoBorderColor),
63
- ),
64
47
padding: const EdgeInsets .all (8 ),
65
48
child: Column (
66
49
children: [
@@ -212,61 +195,23 @@ class InfoView extends StatelessWidget {
212
195
style: CupertinoTheme .of (context).textTheme.textStyle,
213
196
),
214
197
ServingInfoChart (veggie, prefs),
215
- const SizedBox (height: 24 ),
216
- Row (
217
- mainAxisSize: MainAxisSize .min,
218
- children: [
219
- CupertinoSwitch (
220
- value: veggie.isFavorite,
221
- onChanged: (value) {
222
- appState.setFavorite (id, value);
223
- },
224
- ),
225
- const SizedBox (width: 8 ),
226
- Text (
227
- 'Save to Garden' ,
228
- style: CupertinoTheme .of (context).textTheme.textStyle,
229
- ),
230
- ],
231
- ),
232
198
],
233
199
),
234
200
);
235
201
}
236
202
}
237
203
238
- class DetailsScreen extends StatefulWidget {
204
+ class DetailsScreen extends StatelessWidget {
239
205
final int ? id;
240
206
final String ? restorationId;
241
207
242
208
const DetailsScreen ({this .id, this .restorationId, super .key});
243
209
244
- @override
245
- State <DetailsScreen > createState () => _DetailsScreenState ();
246
- }
247
-
248
- class _DetailsScreenState extends State <DetailsScreen > with RestorationMixin {
249
- final RestorableInt _selectedViewIndex = RestorableInt (0 );
250
-
251
- @override
252
- String ? get restorationId => widget.restorationId;
253
-
254
- @override
255
- void restoreState (RestorationBucket ? oldBucket, bool initialRestore) {
256
- registerForRestoration (_selectedViewIndex, 'tab' );
257
- }
258
-
259
- @override
260
- void dispose () {
261
- _selectedViewIndex.dispose ();
262
- super .dispose ();
263
- }
264
-
265
210
Widget _buildHeader (BuildContext context, AppState model) {
266
- final veggie = model.getVeggie (widget. id);
211
+ final veggie = model.getVeggie (id);
267
212
268
213
return SizedBox (
269
- height: 150 ,
214
+ height: 240 ,
270
215
child: Stack (
271
216
children: [
272
217
Positioned (
@@ -287,6 +232,48 @@ class _DetailsScreenState extends State<DetailsScreen> with RestorationMixin {
287
232
}),
288
233
),
289
234
),
235
+ Positioned (
236
+ top: 16 ,
237
+ right: 16 ,
238
+ child: SafeArea (
239
+ child: Row (
240
+ mainAxisSize: MainAxisSize .min,
241
+ children: [
242
+ ShareButton (
243
+ () {
244
+ showCupertinoModalPopup <void >(
245
+ context: context,
246
+ builder: (context) {
247
+ return CupertinoActionSheet (
248
+ title: Text ('Share ${veggie .name }' ),
249
+ message: Text (veggie.shortDescription),
250
+ actions: [
251
+ CupertinoActionSheetAction (
252
+ onPressed: () {
253
+ Navigator .pop (context);
254
+ },
255
+ child: const Text ('OK' ),
256
+ ),
257
+ ],
258
+ );
259
+ },
260
+ );
261
+ },
262
+ ),
263
+ const SizedBox (width: 8 ),
264
+ Builder (builder: (context) {
265
+ final appState = Provider .of <AppState >(context);
266
+ final veggie = appState.getVeggie (id);
267
+
268
+ return FavoriteButton (
269
+ () => appState.setFavorite (id, ! veggie.isFavorite),
270
+ veggie.isFavorite,
271
+ );
272
+ }),
273
+ ],
274
+ ),
275
+ ),
276
+ ),
290
277
],
291
278
),
292
279
);
@@ -296,41 +283,22 @@ class _DetailsScreenState extends State<DetailsScreen> with RestorationMixin {
296
283
Widget build (BuildContext context) {
297
284
final appState = Provider .of <AppState >(context);
298
285
299
- return UnmanagedRestorationScope (
300
- bucket: bucket,
301
- child: CupertinoPageScaffold (
302
- child: Column (
303
- crossAxisAlignment: CrossAxisAlignment .stretch,
304
- mainAxisSize: MainAxisSize .min,
305
- children: [
306
- Expanded (
307
- child: ListView (
308
- restorationId: 'list' ,
309
- children: [
310
- _buildHeader (context, appState),
311
- const SizedBox (height: 20 ),
312
- CupertinoSegmentedControl <int >(
313
- children: const {
314
- 0 : Text (
315
- 'Facts & Info' ,
316
- ),
317
- 1 : Text (
318
- 'Trivia' ,
319
- )
320
- },
321
- groupValue: _selectedViewIndex.value,
322
- onValueChanged: (value) {
323
- setState (() => _selectedViewIndex.value = value);
324
- },
325
- ),
326
- _selectedViewIndex.value == 0
327
- ? InfoView (widget.id)
328
- : TriviaView (id: widget.id, restorationId: 'trivia' ),
329
- ],
330
- ),
286
+ return CupertinoPageScaffold (
287
+ child: Column (
288
+ crossAxisAlignment: CrossAxisAlignment .stretch,
289
+ mainAxisSize: MainAxisSize .min,
290
+ children: [
291
+ Expanded (
292
+ child: ListView (
293
+ restorationId: 'list' ,
294
+ children: [
295
+ _buildHeader (context, appState),
296
+ const SizedBox (height: 20 ),
297
+ InfoView (id),
298
+ ],
331
299
),
332
- ] ,
333
- ) ,
300
+ ) ,
301
+ ] ,
334
302
),
335
303
);
336
304
}
0 commit comments