55import  'package:flutter/cupertino.dart' ;
66import  'package:go_router/go_router.dart' ;
77import  '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' ;
1413
1514class  ServingInfoChart  extends  StatelessWidget  {
1615  const  ServingInfoChart (this .veggie, this .prefs, {super .key});
@@ -44,23 +43,7 @@ class ServingInfoChart extends StatelessWidget {
4443    return  Column (
4544      children:  [
4645        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-         ),
6046        Container (
61-           decoration:  BoxDecoration (
62-             border:  Border .all (color:  Styles .servingInfoBorderColor),
63-           ),
6447          padding:  const  EdgeInsets .all (8 ),
6548          child:  Column (
6649            children:  [
@@ -212,61 +195,23 @@ class InfoView extends StatelessWidget {
212195            style:  CupertinoTheme .of (context).textTheme.textStyle,
213196          ),
214197          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-           ),
232198        ],
233199      ),
234200    );
235201  }
236202}
237203
238- class  DetailsScreen  extends  StatefulWidget  {
204+ class  DetailsScreen  extends  StatelessWidget  {
239205  final  int ?  id;
240206  final  String ?  restorationId;
241207
242208  const  DetailsScreen ({this .id, this .restorationId, super .key});
243209
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- 
265210  Widget  _buildHeader (BuildContext  context, AppState  model) {
266-     final  veggie =  model.getVeggie (widget. id);
211+     final  veggie =  model.getVeggie (id);
267212
268213    return  SizedBox (
269-       height:  150 ,
214+       height:  240 ,
270215      child:  Stack (
271216        children:  [
272217          Positioned (
@@ -287,6 +232,48 @@ class _DetailsScreenState extends State<DetailsScreen> with RestorationMixin {
287232              }),
288233            ),
289234          ),
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+           ),
290277        ],
291278      ),
292279    );
@@ -296,41 +283,22 @@ class _DetailsScreenState extends State<DetailsScreen> with RestorationMixin {
296283  Widget  build (BuildContext  context) {
297284    final  appState =  Provider .of <AppState >(context);
298285
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+               ],
331299            ),
332-           ] ,
333-         ) ,
300+           ) ,
301+         ] ,
334302      ),
335303    );
336304  }
0 commit comments