-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release: merge release into master (#13)
- Loading branch information
Showing
31 changed files
with
1,483 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
enum ClearBasketDialogAction { | ||
no, | ||
yes, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
enum AppTheme { | ||
dark, | ||
light, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,108 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:avon_farm_foods/enums/theme.dart'; | ||
import 'package:avon_farm_foods/models/configuration.dart'; | ||
import 'package:avon_farm_foods/pages/basket.dart'; | ||
import 'package:avon_farm_foods/pages/checkout.dart'; | ||
import 'package:avon_farm_foods/pages/home.dart'; | ||
import 'package:avon_farm_foods/pages/orders.dart'; | ||
import 'package:avon_farm_foods/pages/products.dart'; | ||
import 'package:avon_farm_foods/pages/settings.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
void main() { | ||
runApp( | ||
new FutureBuilder<SharedPreferences>( | ||
builder: ( | ||
BuildContext context, | ||
AsyncSnapshot<SharedPreferences> snapshot, | ||
) { | ||
return snapshot.hasData ? new MyApp(snapshot.data) : new SplashScreen(); | ||
}, | ||
future: SharedPreferences.getInstance(), | ||
), | ||
); | ||
} | ||
|
||
class MyApp extends StatefulWidget { | ||
MyApp(this.preferences); | ||
|
||
final SharedPreferences preferences; | ||
|
||
@override | ||
_MyAppState createState() => new _MyAppState(); | ||
} | ||
|
||
class _MyAppState extends State<MyApp> { | ||
Configuration get _configuration { | ||
if (widget.preferences.getString('configuration') == null) { | ||
Configuration configuration = new Configuration(); | ||
|
||
_configurationUpdater(configuration); | ||
|
||
return configuration; | ||
} else { | ||
return new Configuration.fromJson( | ||
JSON.decode( | ||
widget.preferences.getString('configuration'), | ||
), | ||
); | ||
} | ||
} | ||
|
||
ThemeData get _theme { | ||
switch (_configuration.theme) { | ||
case AppTheme.dark: | ||
return new ThemeData.dark(); | ||
case AppTheme.light: | ||
return new ThemeData.light(); | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
void main() => runApp(new MyApp()); | ||
void _configurationUpdater(Configuration configuration) { | ||
setState(() { | ||
widget.preferences.setString( | ||
'configuration', | ||
JSON.encode(configuration), | ||
); | ||
}); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return new MaterialApp( | ||
home: new HomePage(), | ||
theme: new ThemeData.dark(), | ||
routes: <String, WidgetBuilder>{ | ||
'/basket': (BuildContext context) => new BasketPage(), | ||
'/checkout': (BuildContext context) => new CheckoutPage(), | ||
'/orders': (BuildContext context) => new OrdersPage(), | ||
'/products': (BuildContext context) => new ProductsPage(), | ||
'/settings': (BuildContext context) { | ||
return new SettingsPage( | ||
_configuration, | ||
_configurationUpdater, | ||
); | ||
}, | ||
}, | ||
theme: _theme, | ||
title: 'Avon Farm Foods', | ||
); | ||
} | ||
} | ||
|
||
class SplashScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return new MaterialApp( | ||
home: new Container( | ||
child: new Image.asset( | ||
'images/splash_screen.png', | ||
fit: BoxFit.cover, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Checkout { | ||
String address; | ||
int cardNumber; | ||
int cvv; | ||
String expiryDate; | ||
String firstName; | ||
String lastName; | ||
String postcode; | ||
int telephone; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:avon_farm_foods/enums/theme.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'configuration.g.dart'; | ||
|
||
@JsonSerializable() | ||
class Configuration extends Object with _$ConfigurationSerializerMixin { | ||
Configuration({this.theme = AppTheme.dark}) : assert(theme != null); | ||
|
||
final AppTheme theme; | ||
|
||
factory Configuration.fromJson(Map<String, dynamic> json) { | ||
return _$ConfigurationFromJson(json); | ||
} | ||
|
||
Configuration copyWith({AppTheme theme}) { | ||
return new Configuration(theme: theme ?? this.theme); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:avon_farm_foods/models/product.dart'; | ||
|
||
class Order { | ||
Order({this.id, this.date, this.delivery, this.products, this.total}); | ||
|
||
final int id; | ||
final DateTime date; | ||
final DateTime delivery; | ||
final List<Product> products; | ||
final double total; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class Page { | ||
Page({this.icon, this.route, this.title}); | ||
|
||
final Icon icon; | ||
final String route; | ||
final String title; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Product implements Comparable<Product> { | ||
Product({ | ||
this.description, | ||
this.id, | ||
this.isFavourite = false, | ||
this.isInBasket = false, | ||
this.isPopular = false, | ||
this.name, | ||
this.price, | ||
this.quantity = 0, | ||
this.url, | ||
}); | ||
|
||
final String description; | ||
final int id; | ||
final bool isPopular; | ||
final String name; | ||
final double price; | ||
final String url; | ||
|
||
bool isFavourite; | ||
bool isInBasket; | ||
int quantity; | ||
|
||
@override | ||
int compareTo(Product other) => id - other.id; | ||
|
||
bool operator ==(other) => other is Product && other.id == id; | ||
int get hashCode => id.hashCode; | ||
} |
Oops, something went wrong.