|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 | 15 | import 'package:flutter/material.dart';
|
| 16 | +import 'package:intl/intl.dart'; |
| 17 | + |
| 18 | +import 'model/data.dart'; |
| 19 | +import 'model/product.dart'; |
16 | 20 |
|
17 | 21 | class HomePage extends StatelessWidget {
|
18 |
| - // TODO: Make a collection of cards (102) |
19 | 22 | // TODO: Add a variable for Category (104)
|
20 | 23 |
|
| 24 | + List<Card> _buildGridCards(BuildContext context) { |
| 25 | + List<Product> products = getProducts(Category.all); |
| 26 | + |
| 27 | + if (products == null || products.isEmpty) { |
| 28 | + return <Card>[]; |
| 29 | + } |
| 30 | + |
| 31 | + final ThemeData theme = Theme.of(context); |
| 32 | + final NumberFormat formatter = NumberFormat.simpleCurrency( |
| 33 | + locale: Localizations.localeOf(context).toString()); |
| 34 | + |
| 35 | + return products.map((product) { |
| 36 | + return Card( |
| 37 | + // TODO: Adjust card heights (103) |
| 38 | + child: Column( |
| 39 | + // TODO: Center items on the card (103) |
| 40 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 41 | + children: <Widget>[ |
| 42 | + AspectRatio( |
| 43 | + aspectRatio: 18 / 11, |
| 44 | + child: Image.asset( |
| 45 | + product.assetName, |
| 46 | + package: product.assetPackage, |
| 47 | + fit: BoxFit.fitWidth, |
| 48 | + ), |
| 49 | + ), |
| 50 | + Expanded( |
| 51 | + child: Padding( |
| 52 | + padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0), |
| 53 | + child: Column( |
| 54 | + // TODO: Align labels to the bottom and center (103) |
| 55 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 56 | + // TODO: Change innermost Column (103) |
| 57 | + children: <Widget>[ |
| 58 | + // TODO(larche): Make headline6 when available |
| 59 | + Text( |
| 60 | + product.name, |
| 61 | + style: theme.textTheme.title, |
| 62 | + maxLines: 1, |
| 63 | + ), |
| 64 | + SizedBox(height: 8.0), |
| 65 | + // TODO(larche): Make subtitle2 when available |
| 66 | + Text( |
| 67 | + formatter.format(product.price), |
| 68 | + style: theme.textTheme.body2, |
| 69 | + ), |
| 70 | + ], |
| 71 | + ), |
| 72 | + ), |
| 73 | + ), |
| 74 | + ], |
| 75 | + ), |
| 76 | + ); |
| 77 | + }).toList(); |
| 78 | + } |
| 79 | + |
21 | 80 | @override
|
22 | 81 | Widget build(BuildContext context) {
|
23 | 82 | // TODO: Return an AsymmetricView (104)
|
24 | 83 | // TODO: Pass Category variable to AsymmetricView (104)
|
| 84 | + |
25 | 85 | return Scaffold(
|
26 |
| - // TODO: Add app bar (102) |
27 |
| - // TODO: Add a grid view (102) |
| 86 | + appBar: AppBar( |
| 87 | + leading: IconButton( |
| 88 | + icon: Icon(Icons.menu), |
| 89 | + onPressed: () { |
| 90 | + print('Menu button'); |
| 91 | + }, |
| 92 | + ), |
| 93 | + title: Text('SHRINE'), |
| 94 | + actions: <Widget>[ |
| 95 | + IconButton( |
| 96 | + icon: Icon(Icons.search), |
| 97 | + onPressed: () { |
| 98 | + print('Search button'); |
| 99 | + }, |
| 100 | + ), |
| 101 | + IconButton( |
| 102 | + icon: Icon(Icons.tune), |
| 103 | + onPressed: () { |
| 104 | + print('Filter button'); |
| 105 | + }, |
| 106 | + ), |
| 107 | + ], |
| 108 | + ), |
28 | 109 | body: Center(
|
29 |
| - child: Text('You did it!'), |
| 110 | + child: GridView.count( |
| 111 | + crossAxisCount: 2, |
| 112 | + padding: EdgeInsets.all(16.0), |
| 113 | + childAspectRatio: 8.0 / 9.0, |
| 114 | + children: _buildGridCards(context), |
| 115 | + ), |
30 | 116 | ),
|
31 | 117 | );
|
32 | 118 | }
|
33 | 119 | }
|
34 |
| - |
|
0 commit comments