Compare commits

...

2 commits

6 changed files with 79 additions and 31 deletions

View file

@ -17,6 +17,7 @@
import 'package:buyeeb_mobile/pages/main_page.dart'; import 'package:buyeeb_mobile/pages/main_page.dart';
import 'package:buyeeb_mobile/pages/splash.dart'; import 'package:buyeeb_mobile/pages/splash.dart';
import 'package:buyeeb_mobile/pages/view_listing.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'models/user_listings.dart'; import 'models/user_listings.dart';
@ -30,11 +31,12 @@ void main() {
routes: { routes: {
'/': (context) => RouteHome(), '/': (context) => RouteHome(),
'/splash': (context) => RouteSplash(), '/splash': (context) => RouteSplash(),
'/view_listing': (context) => RouteViewListing(),
}, },
title: "Buypeeb Mobile", title: "Buypeeb Mobile",
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.orange, primarySwatch: Colors.pink,
), ),
) )
), ),

View file

@ -3,17 +3,18 @@ import 'package:buyeeb_mobile/models/yahoo_auctions_item.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
class UserListings extends ChangeNotifier { class UserListings extends ChangeNotifier {
final List<YahooAuctionsItem> _items = []; // final List<YahooAuctionsItem> _items = [];
final Map<String, YahooAuctionsItem> _items = {};
UnmodifiableListView<YahooAuctionsItem> get items => UnmodifiableListView(_items); UnmodifiableMapView<String, YahooAuctionsItem> get items => UnmodifiableMapView(_items);
void add (YahooAuctionsItem item) { void add (String key, YahooAuctionsItem item) {
_items.add(item); _items[key] = item;
notifyListeners(); notifyListeners();
} }
void remove(YahooAuctionsItem item) { void remove(String key) {
_items.remove(item); _items.remove(key);
notifyListeners(); notifyListeners();
} }

View file

@ -1,12 +1,10 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
class YahooAuctionsItem { class YahooAuctionsItem {
String id;
String name; String name;
int price; int price;
YahooAuctionsItem({ YahooAuctionsItem({
@required this.id,
@required this.name, @required this.name,
@required this.price @required this.price
}); });

View file

@ -9,13 +9,7 @@ class RouteHome extends StatelessWidget {
// This widget is the root of your application. // This widget is the root of your application.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MainPage();
title: "Buypeeb",
theme: ThemeData(
primarySwatch: Colors.orange,
),
home: MainPage(),
);
} }
} }
@ -58,13 +52,23 @@ class _MainPageState extends State<MainPage> {
padding: EdgeInsets.all(8.0), padding: EdgeInsets.all(8.0),
separatorBuilder: (context, i) => Divider(), separatorBuilder: (context, i) => Divider(),
itemCount: listings.items.length, itemCount: listings.items.length,
itemBuilder: (context, i) => ListTile( itemBuilder: (context, i) {
title: Text(listings.items[i].name), String key = listings.items.keys.elementAt(i);
subtitle: Text(sprintf( return ListTile(
"¥%d (≈\$%2.2f)", title: Text(listings.items[key].name),
[listings.items[i].price, listings.items[i].getLocalPrice()] subtitle: Text(sprintf(
)), "¥%d (≈\$%2.2f)",
), [listings.items[key].price, listings.items[key].getLocalPrice()]
)),
onTap: () {
Navigator.pushNamed(
context,
'/view_listing',
arguments: key
);
}
);
}
); );
} }
} }

View file

@ -10,26 +10,28 @@ class RouteSplash extends StatefulWidget {
} }
class _RouteSplashState extends State<RouteSplash> { class _RouteSplashState extends State<RouteSplash> {
bool _ready = false;
_loadUserSettings() async { _loadUserSettings() async {
// sleep for a bit to "simulate" loading // sleep for a bit to "simulate" loading
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 2));
// add some random stuff to the listings // add some random stuff to the listings
var listings = context.read<UserListings>(); var listings = context.read<UserListings>();
var _rng = new Random(); var _rng = new Random();
final names = ["Hi Pempa!", "Pebulon Crystal", "The Peebler Chronicles", "Pecha Sludge", "The Forbidden Book of Peebus"]; final names = ["Hi Pempa!", "Pebulon Crystal", "The Peebler Chronicles", "Pecha Sludge", "The Forbidden Book of Peebus"];
for (var i = 0; i < 15; i++) { for (var i = 0; i < 15; i++) {
listings.add(YahooAuctionsItem( listings.add(
id: "Henlo", "k" + (_rng.nextInt(500000) + 100000).toString(),
YahooAuctionsItem(
name: names[_rng.nextInt(names.length)], name: names[_rng.nextInt(names.length)],
price: _rng.nextInt(5000) + 500 price: _rng.nextInt(5000) + 500
)); ));
} }
setState(() { setState(() {
_ready = true; Navigator.pushNamedAndRemoveUntil(
Navigator.pushNamed(context, '/'); context,
'/',
(Route<dynamic> route) => false,
);
}); });
} }
@ -43,7 +45,22 @@ class _RouteSplashState extends State<RouteSplash> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: Center( body: Center(
child: CircularProgressIndicator(), child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: const EdgeInsets.all(12.0),
child: Text(
"Buypeeb Mobile",
style: TextStyle(
fontSize: 36.0,
fontWeight: FontWeight.w200
),
),
),
CircularProgressIndicator(),
]
)
) )
); );
} }

View file

@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
class RouteViewListing extends StatefulWidget {
@override
_RouteViewListingState createState() => _RouteViewListingState();
}
class _RouteViewListingState extends State<RouteViewListing> {
@override
Widget build(BuildContext context) {
final String id = ModalRoute.of(context).settings.arguments;
return Scaffold(
appBar: AppBar(
title: Text("View listing"),
automaticallyImplyLeading: false, // remove the useless back button
),
body: ListView(
children: [
ListTile(
title: Text("ID: $id")
)
]
)
);
}
}