|
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 | import 'model/data.dart';
|
18 | 22 | import 'model/product.dart';
|
19 | 23 | import 'supplemental/asymmetric_view.dart';
|
20 | 24 |
|
21 | 25 | class HomePage extends StatelessWidget {
|
| 26 | + |
| 27 | + List<Card> _buildGridCards(BuildContext context) { |
| 28 | + List<Product> products = getProducts(Category.all); |
| 29 | + |
| 30 | + if (products == null || products.isEmpty) { |
| 31 | + return const <Card>[]; |
| 32 | + } |
| 33 | + |
| 34 | + final ThemeData theme = Theme.of(context); |
| 35 | + final NumberFormat formatter = NumberFormat.simpleCurrency( |
| 36 | + locale: Localizations.localeOf(context).toString()); |
| 37 | + |
| 38 | + return products.map((product) { |
| 39 | + return Card( |
| 40 | + child: Column( |
| 41 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 42 | + children: <Widget>[ |
| 43 | + AspectRatio( |
| 44 | + aspectRatio: 18 / 11, |
| 45 | + child: Image.asset( |
| 46 | + product.assetName, |
| 47 | + package: product.assetPackage, |
| 48 | + fit: BoxFit.fitWidth, |
| 49 | + ), |
| 50 | + ), |
| 51 | + Expanded( |
| 52 | + child: Padding( |
| 53 | + padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0), |
| 54 | + child: Column( |
| 55 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 56 | + children: <Widget>[ |
| 57 | + // TODO(larche): Make headline6 when available |
| 58 | + Text( |
| 59 | + product.name, |
| 60 | + style: theme.textTheme.title, |
| 61 | + maxLines: 1, |
| 62 | + ), |
| 63 | + SizedBox(height: 8.0), |
| 64 | + // TODO(larche): Make subtitle2 when available |
| 65 | + Text( |
| 66 | + formatter.format(product.price), |
| 67 | + style: theme.textTheme.body2, |
| 68 | + ), |
| 69 | + ], |
| 70 | + ), |
| 71 | + ), |
| 72 | + ), |
| 73 | + ], |
| 74 | + ), |
| 75 | + ); |
| 76 | + }).toList(); |
| 77 | + } |
| 78 | + |
22 | 79 | @override
|
23 | 80 | Widget build(BuildContext context) {
|
24 | 81 | return Scaffold(
|
|
0 commit comments