Advertisement
wahyuabrory

recipe_detail.dart 10riceappjatim

Mar 22nd, 2024 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.10 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'recipe.dart';
  3.  
  4. class RecipeDetail extends StatefulWidget {
  5.   final Recipe recipe;
  6.  
  7.   const RecipeDetail({super.key, required this.recipe});
  8.  
  9.   @override
  10.   _RecipeDetailState createState() => _RecipeDetailState();
  11. }
  12.  
  13. class _RecipeDetailState extends State<RecipeDetail> {
  14.   int _sliderVal = 1;
  15.  
  16.   @override
  17.   Widget build(BuildContext context) {
  18.     return Scaffold(
  19.       appBar: AppBar(
  20.         title: Text(widget.recipe.label),
  21.       ),
  22.       body: SingleChildScrollView(
  23.         child: Column(
  24.           crossAxisAlignment: CrossAxisAlignment.stretch,
  25.           children: [
  26.             SizedBox(
  27.               height: 300,
  28.               width: double.infinity,
  29.               child: Image.asset(
  30.                 widget.recipe.imageUrl,
  31.                 fit: BoxFit.cover,
  32.               ),
  33.             ),
  34.             Padding(
  35.               padding: const EdgeInsets.all(16.0),
  36.               child: Text(
  37.                 widget.recipe.label,
  38.                 style: const TextStyle(
  39.                   fontSize: 24,
  40.                   fontWeight: FontWeight.bold,
  41.                 ),
  42.               ),
  43.             ),
  44.             Padding(
  45.               padding: const EdgeInsets.symmetric(horizontal: 16.0),
  46.               child: Column(
  47.                 crossAxisAlignment: CrossAxisAlignment.start,
  48.                 children: [
  49.                   const Text(
  50.                     'Ingredients:',
  51.                     style: TextStyle(
  52.                       fontSize: 20,
  53.                       fontWeight: FontWeight.bold,
  54.                     ),
  55.                   ),
  56.                   const SizedBox(height: 8),
  57.                   ListView.builder(
  58.                     shrinkWrap: true,
  59.                     itemCount: widget.recipe.ingredients.length,
  60.                     itemBuilder: (BuildContext context, int index) {
  61.                       final ingredient = widget.recipe.ingredients[index];
  62.                       return ListTile(
  63.                         leading: const Icon(Icons.check_circle),
  64.                         title: Text(
  65.                           '${ingredient.quantity * _sliderVal} ${ingredient.measure} ${ingredient.name}',
  66.                           style: const TextStyle(fontSize: 18),
  67.                         ),
  68.                       );
  69.                     },
  70.                   ),
  71.                   const SizedBox(height: 16),
  72.                   Slider(
  73.                     min: 1,
  74.                     max: 10,
  75.                     divisions: 10,
  76.                     value: _sliderVal.toDouble(),
  77.                     activeColor: Colors.green,
  78.                     inactiveColor: Colors.grey[
  79.                         300],
  80.                     label:
  81.                         '${_sliderVal * widget.recipe.servings} servings',
  82.                     onChanged: (newValue) {
  83.                       setState(() {
  84.                         _sliderVal = newValue.round();
  85.                       });
  86.                     },
  87.                   ),
  88.                 ],
  89.               ),
  90.             ),
  91.           ],
  92.         ),
  93.       ),
  94.     );
  95.   }
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement