|
1 |
| -import 'dart:io'; |
2 |
| - |
3 | 1 | import 'package:flutter/cupertino.dart';
|
4 | 2 | import 'package:flutter/material.dart';
|
| 3 | +import 'package:food_recipe/src/blocs/list_meals_bloc.dart'; |
| 4 | +import 'package:food_recipe/src/models/categories/categories.dart'; |
| 5 | +import 'package:food_recipe/src/models/filtercategories/filter_categories.dart'; |
| 6 | +import 'package:food_recipe/src/utils/utils.dart'; |
5 | 7 |
|
6 | 8 | class ListMeals extends StatefulWidget {
|
7 | 9 | @override
|
8 | 10 | _ListMealsState createState() => _ListMealsState();
|
9 | 11 | }
|
10 | 12 |
|
11 | 13 | class _ListMealsState extends State<ListMeals> {
|
| 14 | + CategoryItem categoryItem; |
| 15 | + |
| 16 | + @override |
| 17 | + void initState() { |
| 18 | + super.initState(); |
| 19 | + } |
| 20 | + |
12 | 21 | @override
|
13 | 22 | Widget build(BuildContext context) {
|
14 | 23 | var mediaQuery = MediaQuery.of(context);
|
| 24 | + categoryItem = ModalRoute.of(context).settings.arguments; |
| 25 | + |
15 | 26 | return Scaffold(
|
16 | 27 | body: Container(
|
17 | 28 | width: double.infinity,
|
18 | 29 | height: double.infinity,
|
19 | 30 | child: Stack(
|
20 | 31 | children: <Widget>[
|
21 | 32 | _buildWidgetBackgroundCircle(mediaQuery),
|
22 |
| - _buildWidgetArrowBackMenu(), |
| 33 | + _buildWidgetContent(mediaQuery), |
23 | 34 | ],
|
24 | 35 | ),
|
25 | 36 | ),
|
26 | 37 | );
|
27 | 38 | }
|
28 | 39 |
|
29 |
| - Widget _buildWidgetArrowBackMenu() { |
| 40 | + Widget _buildWidgetContent(MediaQueryData mediaQuery) { |
30 | 41 | return SafeArea(
|
31 |
| - minimum: EdgeInsets.symmetric(horizontal: 16.0), |
32 |
| - child: CircleAvatar( |
33 |
| - child: Platform.isIOS |
34 |
| - ? Icon(Icons.arrow_back_ios, color: Colors.black) |
35 |
| - : Icon(Icons.arrow_back, color: Colors.black), |
36 |
| - maxRadius: 24.0, |
37 |
| - backgroundColor: Colors.white, |
| 42 | + minimum: EdgeInsets.symmetric(horizontal: 16.0), |
| 43 | + child: Column( |
| 44 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 45 | + children: <Widget>[ |
| 46 | + Padding(padding: EdgeInsets.only(top: 16.0)), |
| 47 | + Text( |
| 48 | + categoryItem.strCategory, |
| 49 | + style: Theme.of(context) |
| 50 | + .textTheme |
| 51 | + .display2 |
| 52 | + .merge(TextStyle(fontWeight: FontWeight.bold)), |
| 53 | + maxLines: 1, |
| 54 | + ), |
| 55 | + Padding(padding: EdgeInsets.only(top: 16.0)), |
| 56 | + Expanded( |
| 57 | + child: FutureBuilder( |
| 58 | + future: |
| 59 | + listMealsBloc.getFilterCategories(categoryItem.strCategory), |
| 60 | + builder: (BuildContext context, |
| 61 | + AsyncSnapshot<FilterCategories> snapshot) { |
| 62 | + if (snapshot.hasData) { |
| 63 | + FilterCategories filterCategories = snapshot.data; |
| 64 | + return ListView.builder( |
| 65 | + shrinkWrap: true, |
| 66 | + itemCount: filterCategories.filterCategoryItems.length, |
| 67 | + itemBuilder: (context, index) { |
| 68 | + FilterCategoryItem filterCategoryItem = |
| 69 | + filterCategories.filterCategoryItems[index]; |
| 70 | + return Padding( |
| 71 | + padding: const EdgeInsets.only(bottom: 16.0), |
| 72 | + child: Card( |
| 73 | + elevation: 8.0, |
| 74 | + shape: RoundedRectangleBorder( |
| 75 | + borderRadius: BorderRadius.circular(16.0), |
| 76 | + ), |
| 77 | + child: ClipRRect( |
| 78 | + borderRadius: BorderRadius.circular(16.0), |
| 79 | + child: Stack( |
| 80 | + children: <Widget>[ |
| 81 | + FadeInImage( |
| 82 | + image: NetworkImage( |
| 83 | + filterCategoryItem.strMealThumb), |
| 84 | + placeholder: AssetImage( |
| 85 | + "assets/images/img_not_found.jpg"), |
| 86 | + fit: BoxFit.cover, |
| 87 | + width: double.infinity, |
| 88 | + height: mediaQuery.size.width / 1.5, |
| 89 | + ), |
| 90 | + Container( |
| 91 | + width: double.infinity, |
| 92 | + height: mediaQuery.size.width / 1.5, |
| 93 | + decoration: BoxDecoration( |
| 94 | + gradient: LinearGradient( |
| 95 | + begin: Alignment.topCenter, |
| 96 | + end: Alignment.bottomCenter, |
| 97 | + stops: [ |
| 98 | + 0.1, |
| 99 | + 0.9 |
| 100 | + ], |
| 101 | + colors: [ |
| 102 | + Color(0xFFFFFFFF), |
| 103 | + Color(0x00FFFFFF), |
| 104 | + ]), |
| 105 | + ), |
| 106 | + ), |
| 107 | + Padding( |
| 108 | + padding: const EdgeInsets.all(16.0), |
| 109 | + child: Row( |
| 110 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 111 | + children: <Widget>[ |
| 112 | + Expanded( |
| 113 | + child: Text( |
| 114 | + filterCategoryItem.strMeal, |
| 115 | + style: |
| 116 | + Theme.of(context).textTheme.title, |
| 117 | + maxLines: 2, |
| 118 | + ), |
| 119 | + ), |
| 120 | + GestureDetector( |
| 121 | + onTap: () { |
| 122 | + // TODO: do something in here |
| 123 | + }, |
| 124 | + child: CircleAvatar( |
| 125 | + backgroundColor: Color(0xAFE8364B), |
| 126 | + child: Icon( |
| 127 | + Icons.favorite_border, |
| 128 | + color: Colors.white, |
| 129 | + ), |
| 130 | + ), |
| 131 | + ), |
| 132 | + ], |
| 133 | + ), |
| 134 | + ), |
| 135 | + ], |
| 136 | + ), |
| 137 | + ), |
| 138 | + ), |
| 139 | + ); |
| 140 | + }, |
| 141 | + ); |
| 142 | + } else if (snapshot.hasError) { |
| 143 | + return Text(snapshot.error.toString()); |
| 144 | + } |
| 145 | + return Center(child: buildCircularProgressIndicator()); |
| 146 | + }, |
38 | 147 | ),
|
39 |
| - ); |
| 148 | + ), |
| 149 | + ], |
| 150 | + ), |
| 151 | + ); |
40 | 152 | }
|
41 | 153 |
|
42 | 154 | Widget _buildWidgetBackgroundCircle(MediaQueryData mediaQuery) {
|
|
0 commit comments