Skip to content

[102] Complete #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f6ae733
[102] Buttons for AppBar.
willlarche Mar 31, 2018
8e7b4f1
[102] Copy correction.
willlarche Mar 31, 2018
8dd59af
[102] Almost complete layout.
willlarche Apr 1, 2018
fc52587
[102] Starting data model.
willlarche Apr 2, 2018
2251d54
[102] Formatting.
willlarche Apr 2, 2018
12f0fcd
[102] Dummy data.
willlarche Apr 2, 2018
86a116c
[102] Fake data.
willlarche Apr 3, 2018
dea9829
[102] Formatting
willlarche Apr 3, 2018
e144815
[102] Card currency formatting.
willlarche Apr 3, 2018
8951bf4
[102] Starting to make the currency localized.
willlarche Apr 4, 2018
c5ccaaf
[102] Pubspec for intl.
willlarche Apr 4, 2018
7976303
[102] Data work.
willlarche Apr 4, 2018
08ae71b
[102] Home layout
willlarche Apr 4, 2018
23adcf4
[102] Formatting
willlarche Apr 4, 2018
2618336
[102] Data.
willlarche Apr 4, 2018
98e6ca6
[102] Formatting.
willlarche Apr 5, 2018
c2b4dba
[102] Sync.
willlarche Apr 5, 2018
dacac60
[102] Formatting.
willlarche Apr 5, 2018
fff531c
[102] PR feedback.
willlarche Apr 5, 2018
f5b3f9a
[102] Minor refactor for data.
willlarche Apr 6, 2018
3e1a1b4
[102] Formatting.
willlarche Apr 6, 2018
1347451
[102] PR Feedback (trailing commas)
willlarche Apr 6, 2018
5d117c7
[102] Improving formatting and simplifying data model.
willlarche Apr 6, 2018
fea05d5
[102] Comment.
willlarche Apr 6, 2018
af8ea45
[102] Sync.
willlarche Apr 7, 2018
c19446d
[102] Import order correction.
willlarche Apr 7, 2018
8e74c3b
[102] PR feedback.
willlarche Apr 9, 2018
1932f9e
[102] PR feedback.
willlarche Apr 9, 2018
f4a9272
[102] PR feedback around localization.
willlarche Apr 10, 2018
8047261
[102] PR feedback.
willlarche Apr 10, 2018
daf393d
[102] PR feedback.
willlarche Apr 10, 2018
1b35cb7
[102] PR feedback.
willlarche Apr 10, 2018
f87f765
[102] Better support for smaller screens.
willlarche Apr 10, 2018
f6abd24
[102] Simplifying creation of cards.
willlarche Apr 10, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions MDC-102/complete/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
.atom/
.dart_tool/
.idea
.vscode/
.packages
.pub/
build/
ios/.generated/
packages
.flutter-plugins
8 changes: 8 additions & 0 deletions MDC-102/complete/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 5a58b36e36b8d7aace89d3950e6deb307956a6a0
channel: beta
Binary file added MDC-102/complete/assets/0-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MDC-102/complete/assets/1-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MDC-102/complete/assets/2-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MDC-102/complete/assets/2.0x/diamond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MDC-102/complete/assets/3-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MDC-102/complete/assets/3.0x/diamond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MDC-102/complete/assets/diamond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions MDC-102/complete/lib/app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';

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

class ShrineApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Shrine',
home: HomePage(),
initialRoute: '/login',
onGenerateRoute: _getRoute,
);
}

Route<dynamic> _getRoute(RouteSettings settings) {
if (settings.name != '/login') {
return null;
}

return MaterialPageRoute<void>(
settings: settings,
builder: (BuildContext context) => LoginPage(),
fullscreenDialog: true,
);
}
}
101 changes: 101 additions & 0 deletions MDC-102/complete/lib/home.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

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

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
List<Card> _buildGridCards() {
List<Product> products = getAllProducts();

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

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

return products.map((product) {
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
AspectRatio(
aspectRatio: 18 / 11,
child: Image.asset(
'assets/${product.id}-1.jpg',
fit: BoxFit.fitWidth,
),
),
Expanded(
child: Padding(
padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// TODO(larche): Make headline6 when available
Text(
product.name,
style: theme.textTheme.title,
maxLines: 1,
),
SizedBox(height: 8.0),
// TODO(larche): Make subtitle2 when available
Text(
formatter.format(product.price),
style: theme.textTheme.body2,
),
],
),
),
),
],
),
);
}).toList();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () {
print('Menu button');
},
),
title: Text('SHRINE'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {
print('Search button');
},
),
IconButton(
icon: Icon(Icons.tune),
onPressed: () {
print('Filter button');
},
),
],
),
body: Center(
child: GridView.count(
crossAxisCount: 2,
children: _buildGridCards(),
padding: EdgeInsets.all(16.0),
mainAxisSpacing: 8.0,
childAspectRatio: 8.0 / 9.0,
),
),
);
}
}
53 changes: 53 additions & 0 deletions MDC-102/complete/lib/login.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';

class LoginPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: ListView(
padding: EdgeInsets.symmetric(horizontal: 24.0),
children: <Widget>[
SizedBox(height: 80.0),
Column(
children: <Widget>[
Image.asset('assets/diamond.png'),
SizedBox(height: 16.0),
Text('SHRINE'),
],
),
SizedBox(height: 120.0),
TextField(
decoration: InputDecoration(
filled: true,
labelText: 'Username',
),
),
SizedBox(height: 12.0),
TextField(
decoration: InputDecoration(
filled: true,
labelText: 'Password',
),
obscureText: true,
),
ButtonBar(
children: <Widget>[
FlatButton(
child: Text('CANCEL'),
onPressed: null,
),
RaisedButton(
child: Text('NEXT'),
onPressed: () {
Navigator.pop(context);
},
),
],
)
],
),
),
);
}
}
5 changes: 5 additions & 0 deletions MDC-102/complete/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:flutter/material.dart';

import 'app.dart';

void main() => runApp(ShrineApp());
34 changes: 34 additions & 0 deletions MDC-102/complete/lib/model/data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'product.dart';

List<Product> getAllProducts() {
return <Product>[
Product(
category: Category.home,
id: 0,
isFeatured: true,
name: 'Tab Can',
price: 35,
),
Product(
category: Category.accessories,
id: 1,
isFeatured: false,
name: 'Pineapple Wallpaper',
price: 80,
),
Product(
category: Category.clothing,
id: 2,
isFeatured: false,
name: 'Tab & Fresca Cooler',
price: 100,
),
Product(
category: Category.home,
id: 3,
isFeatured: false,
name: 'Capris',
price: 5,
),
];
}
26 changes: 26 additions & 0 deletions MDC-102/complete/lib/model/product.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/foundation.dart';

enum Category { none, accessories, clothing, home }

class Product {
const Product({
@required this.category,
@required this.id,
@required this.isFeatured,
@required this.name,
@required this.price,
}) : assert(category != null),
assert(id != null),
assert(isFeatured != null),
assert(name != null),
assert(price != null);

final Category category;
final int id;
final bool isFeatured;
final String name;
final int price;

@override
String toString() => "$name (id=$id)";
}
23 changes: 23 additions & 0 deletions MDC-102/complete/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: mdc_101_complete
description: >
Learn the basics of using Material Components by building a simple app with core components.

dependencies:
flutter:
sdk: flutter
intl: "^0.15.4"

cupertino_icons: ^0.1.0

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
assets:
- assets/diamond.png
- assets/0-1.jpg
- assets/1-1.jpg
- assets/2-1.jpg
- assets/3-1.jpg