diff --git a/lib/main.dart b/lib/main.dart
index 5649543..3454589 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -15,75 +15,33 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
+import 'package:buyeeb_mobile/pages/main_page.dart';
+import 'package:buyeeb_mobile/pages/splash.dart';
import 'package:flutter/material.dart';
import 'package:sprintf/sprintf.dart';
-import 'yahoo_auctions_item.dart';
+import 'package:provider/provider.dart';
+import 'models/yahoo_auctions_item.dart';
+import 'models/user_listings.dart';
+import 'package:sqflite/sqflite.dart';
import 'dart:math';
+import 'dart:collection';
void main() {
- runApp(MyApp());
-}
-
-class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: "Buypeeb",
- theme: ThemeData(
- primarySwatch: Colors.orange,
- ),
- home: MainPage(),
- );
- }
-}
-
-class MainPage extends StatefulWidget {
- @override
- _MainPageState createState() => _MainPageState();
-}
-
-class _MainPageState extends State {
- final _items = [];
- final _rng = new Random();
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(title: Text("Buypeeb"), actions: [
- IconButton(
- icon: Icon(Icons.search),
- onPressed: () => null,
- tooltip: "Search",
- ),
- IconButton(
- icon: Icon(Icons.list),
- onPressed: () => null,
- tooltip: "Filter",
- ),
- IconButton(
- icon: Icon(Icons.settings),
- onPressed: () => null,
- tooltip: "Settings",
- )
- ]),
- body: _buildAuctionListings(),
- );
- }
-
- Widget _buildAuctionListings() {
- return ListView.builder(
- padding: EdgeInsets.all(16.0),
- itemBuilder: (context, i) {
- if (i.isOdd) return Divider();
-
- final newItem = YahooAuctionsItem(id: "Henlo", name: "Hi Pempa!", price: _rng.nextInt(5000) + 500);
-
- _items.add(newItem);
-
- return ListTile(title: Text(newItem.name),
- subtitle: Text(sprintf("¥%d (≈\$%2.2f)", [newItem.price, newItem.getLocalPrice()])));
- },
- );
- }
+ runApp(
+ ChangeNotifierProvider(
+ create: (context) => UserListings(),
+ child: MaterialApp(
+ initialRoute: '/splash',
+ routes: {
+ '/': (context) => RouteHome(),
+ '/splash': (context) => RouteSplash(),
+ },
+
+ title: "Buypeeb Mobile",
+ theme: ThemeData(
+ primarySwatch: Colors.orange,
+ ),
+ )
+ ),
+ );
}
diff --git a/lib/models/user_listings.dart b/lib/models/user_listings.dart
new file mode 100644
index 0000000..2d34e7b
--- /dev/null
+++ b/lib/models/user_listings.dart
@@ -0,0 +1,24 @@
+import 'dart:collection';
+import 'package:buyeeb_mobile/models/yahoo_auctions_item.dart';
+import 'package:flutter/foundation.dart';
+
+class UserListings extends ChangeNotifier {
+ final List _items = [];
+
+ UnmodifiableListView get items => UnmodifiableListView(_items);
+
+ void add (YahooAuctionsItem item) {
+ _items.add(item);
+ notifyListeners();
+ }
+
+ void remove(YahooAuctionsItem item) {
+ _items.remove(item);
+ notifyListeners();
+ }
+
+ void removeAll() {
+ _items.clear();
+ notifyListeners();
+ }
+}
\ No newline at end of file
diff --git a/lib/yahoo_auctions_item.dart b/lib/models/yahoo_auctions_item.dart
similarity index 100%
rename from lib/yahoo_auctions_item.dart
rename to lib/models/yahoo_auctions_item.dart
diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart
new file mode 100644
index 0000000..102713f
--- /dev/null
+++ b/lib/pages/main_page.dart
@@ -0,0 +1,79 @@
+import 'package:buyeeb_mobile/models/user_listings.dart';
+import 'package:buyeeb_mobile/models/yahoo_auctions_item.dart';
+import 'package:flutter/material.dart';
+import 'package:sprintf/sprintf.dart';
+import 'package:provider/provider.dart';
+import 'dart:math';
+
+class RouteHome extends StatelessWidget {
+ // This widget is the root of your application.
+ @override
+ Widget build(BuildContext context) {
+ return MaterialApp(
+ title: "Buypeeb",
+ theme: ThemeData(
+ primarySwatch: Colors.orange,
+ ),
+ home: MainPage(),
+ );
+ }
+}
+
+class MainPage extends StatefulWidget {
+ @override
+ _MainPageState createState() => _MainPageState();
+}
+
+class _MainPageState extends State {
+ final _items = [];
+ final _rng = new Random();
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: AppBar(title: Text("Buypeeb"), actions: [
+ IconButton(
+ icon: Icon(Icons.search),
+ onPressed: () => null,
+ tooltip: "Search",
+ ),
+ IconButton(
+ icon: Icon(Icons.list),
+ onPressed: () => null,
+ tooltip: "Filter",
+ ),
+ IconButton(
+ icon: Icon(Icons.settings),
+ onPressed: () => null,
+ tooltip: "Settings",
+ )
+ ]),
+ body: _buildAuctionListings(),
+ );
+ }
+
+ Widget _buildAuctionListings() {
+ var listings = context.watch();
+ return ListView.builder(
+ padding: EdgeInsets.all(16.0),
+ // itemBuilder: (context, i) {
+ // if (i.isOdd) return Divider();
+ //
+ // final newItem = YahooAuctionsItem(id: "Henlo", name: "Hi Pempa!", price: _rng.nextInt(5000) + 500);
+ //
+ // _items.add(newItem);
+ //
+ // return ListTile(title: Text(newItem.name),
+ // subtitle: Text(sprintf("¥%d (≈\$%2.2f)", [newItem.price, newItem.getLocalPrice()])));
+ // },
+ itemCount: listings.items.length,
+ itemBuilder: (context, i) => ListTile(
+ title: Text(listings.items[i].name),
+ subtitle: Text(sprintf(
+ "¥%d (≈\$%2.2f)",
+ [listings.items[i].price, listings.items[i].getLocalPrice()]
+ )),
+ ),
+ );
+ }
+}
diff --git a/lib/pages/splash.dart b/lib/pages/splash.dart
new file mode 100644
index 0000000..c0b87fd
--- /dev/null
+++ b/lib/pages/splash.dart
@@ -0,0 +1,50 @@
+import 'package:buyeeb_mobile/models/user_listings.dart';
+import 'package:buyeeb_mobile/models/yahoo_auctions_item.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+import 'dart:math';
+
+class RouteSplash extends StatefulWidget {
+ @override
+ _RouteSplashState createState() => _RouteSplashState();
+}
+
+class _RouteSplashState extends State {
+ bool _ready = false;
+
+ _loadUserSettings() async {
+ // sleep for a bit to "simulate" loading
+ await Future.delayed(Duration(seconds: 3));
+ // add some random stuff to the listings
+ var listings = context.read();
+ var _rng = new Random();
+ final names = ["Hi Pempa!", "Pebulon Crystal", "The Peebler Chronicles", "Pecha Sludge", "The Forbidden Book of Peebus"];
+ for (var i = 0; i < 15; i++) {
+ listings.add(YahooAuctionsItem(
+ id: "Henlo",
+ name: names[_rng.nextInt(names.length)],
+ price: _rng.nextInt(5000) + 500
+ ));
+ }
+
+ setState(() {
+ _ready = true;
+ Navigator.pushNamed(context, '/');
+ });
+ }
+
+ @override
+ void initState() {
+ super.initState();
+ _loadUserSettings();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: Center(
+ child: CircularProgressIndicator(),
+ )
+ );
+ }
+}
diff --git a/pubspec.lock b/pubspec.lock
index bf07431..a1edecd 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -81,6 +81,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
+ nested:
+ dependency: transitive
+ description:
+ name: nested
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.0.4"
path:
dependency: transitive
description:
@@ -88,6 +95,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
+ provider:
+ dependency: "direct main"
+ description:
+ name: provider
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "4.3.2+2"
sky_engine:
dependency: transitive
description: flutter
@@ -107,6 +121,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
+ sqflite:
+ dependency: "direct main"
+ description:
+ name: sqflite
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.3.1+1"
+ sqflite_common:
+ dependency: transitive
+ description:
+ name: sqflite_common
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.0.2+1"
stack_trace:
dependency: transitive
description:
@@ -128,6 +156,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
+ synchronized:
+ dependency: transitive
+ description:
+ name: synchronized
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.2.0+2"
term_glyph:
dependency: transitive
description:
@@ -158,3 +193,4 @@ packages:
version: "2.0.8"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
+ flutter: ">=1.16.0 <2.0.0"
diff --git a/pubspec.yaml b/pubspec.yaml
index c119580..b15f777 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -29,6 +29,8 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
sprintf: "^4.0.0"
+ provider: ^4.1.0
+ sqflite: ^1.3.0
dev_dependencies:
flutter_test:
diff --git a/test/widget_test.dart b/test/widget_test.dart
index a781ca8..bba81a1 100644
--- a/test/widget_test.dart
+++ b/test/widget_test.dart
@@ -5,6 +5,7 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
+import 'package:buyeeb_mobile/pages/main_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -13,7 +14,7 @@ import 'package:buyeeb_mobile/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
- await tester.pumpWidget(MyApp());
+ await tester.pumpWidget(RouteHome());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);