Skip to content

Commit

Permalink
after meal.
Browse files Browse the repository at this point in the history
  • Loading branch information
haidar committed Mar 22, 2019
1 parent 03d3551 commit bd2abe9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 5 deletions.
24 changes: 22 additions & 2 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import 'package:flutter/material.dart';

import 'home.dart';
import 'login.dart';
import 'colors.dart';

// TODO: Convert ShrineApp to stateful widget (104)
class ShrineApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down Expand Up @@ -48,5 +48,25 @@ class ShrineApp extends StatelessWidget {
}
}

// TODO: Build a Shrine Theme (103)
final ThemeData _kShrineTheme = _buildShrineTheme();

ThemeData _buildShrineTheme() {
final ThemeData base = ThemeData.light();
return base.copyWith(
accentColor: kShrineBrown900,
primaryColor: kShrinePink100,
buttonTheme: base.buttonTheme.copyWith(
buttonColor: kShrinePink100,
textTheme: ButtonTextTheme.normal,
),
scaffoldBackgroundColor: kShrineBackgroundWhite,
cardColor: kShrineBackgroundWhite,
textSelectionColor: kShrinePink100,
errorColor: kShrineErrorRed,
// TODO: Add the text themes (103)
// TODO: Add the icon themes (103)
// TODO: Decorate the inputs (103)
);
}

// TODO: Build a Shrine Text Theme (103)
13 changes: 13 additions & 0 deletions lib/colors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter/material.dart';

const kShrinePink50 = const Color(0xFFFEEAE6);
const kShrinePink100 = const Color(0xFFFEDBD0);
const kShrinePink300 = const Color(0xFFFBB8AC);
const kShrinePink400 = const Color(0xFFEAA4A4);

const kShrineBrown900 = const Color(0xFF442B2D);

const kShrineErrorRed = const Color(0xFFC5032B);

const kShrineSurfaceWhite = const Color(0xFFFFFBFA);
const kShrineBackgroundWhite = Colors.white;
59 changes: 56 additions & 3 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
// limitations under the License.

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import 'model/products_repository.dart';
import 'model/product.dart';

class HomePage extends StatelessWidget {
// TODO: Make a collection of cards (102)
// TODO: Add a variable for Category (104)
@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -57,11 +60,11 @@ class HomePage extends StatelessWidget {
crossAxisCount: 2,
padding: EdgeInsets.all(16.0),
childAspectRatio: 8.0 / 9.0,
children: _buildGridCards(10),
children: _buildGridCards(context),
));
}

List<Card> _buildGridCards(int count) {
/* List<Card> _buildGridCards(int count) {
List<Card> cards = List.generate(
count,
(int index) => Card(
Expand All @@ -88,5 +91,55 @@ class HomePage extends StatelessWidget {
),
));
return cards;
}*/
List<Card> _buildGridCards(BuildContext context) {
List<Product> product = ProductsRepository.loadProducts(Category.all);

if (product == null || product.isEmpty) {
return const <Card>[];
}

final ThemeData theme = Theme.of(context);
final NumberFormat formatter = NumberFormat.simpleCurrency(
locale: Localizations.localeOf(context).toString());

return product.map((product) {
return Card(
clipBehavior: Clip.antiAlias,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
AspectRatio(
aspectRatio: 18 / 11,
child: Image.asset(
product.assetName,
package: product.assetPackage,
fit: BoxFit.fitWidth,
),
),
Expanded(
child: Padding(
padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
product.name,
style: theme.textTheme.title,
maxLines: 1,
),
SizedBox(height: 8.0),
Text(
formatter.format(product.price),
style: theme.textTheme.body2,
),
],
),
),
),
],
),
);
}).toList();
}
}

0 comments on commit bd2abe9

Please sign in to comment.