diff --git a/lib/main.dart b/lib/main.dart index 04e440d..75d84e5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,6 +17,7 @@ import 'package:buyeeb_mobile/pages/main_page.dart'; import 'package:buyeeb_mobile/pages/splash.dart'; +import 'package:buyeeb_mobile/pages/view_listing.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'models/user_listings.dart'; @@ -30,6 +31,7 @@ void main() { routes: { '/': (context) => RouteHome(), '/splash': (context) => RouteSplash(), + '/view_listing': (context) => RouteViewListing(), }, title: "Buypeeb Mobile", diff --git a/lib/models/user_listings.dart b/lib/models/user_listings.dart index 2d34e7b..6fc8d9f 100644 --- a/lib/models/user_listings.dart +++ b/lib/models/user_listings.dart @@ -3,17 +3,18 @@ import 'package:buyeeb_mobile/models/yahoo_auctions_item.dart'; import 'package:flutter/foundation.dart'; class UserListings extends ChangeNotifier { - final List _items = []; + // final List _items = []; + final Map _items = {}; - UnmodifiableListView get items => UnmodifiableListView(_items); + UnmodifiableMapView get items => UnmodifiableMapView(_items); - void add (YahooAuctionsItem item) { - _items.add(item); + void add (String key, YahooAuctionsItem item) { + _items[key] = item; notifyListeners(); } - void remove(YahooAuctionsItem item) { - _items.remove(item); + void remove(String key) { + _items.remove(key); notifyListeners(); } diff --git a/lib/models/yahoo_auctions_item.dart b/lib/models/yahoo_auctions_item.dart index 5c90985..32e8358 100644 --- a/lib/models/yahoo_auctions_item.dart +++ b/lib/models/yahoo_auctions_item.dart @@ -1,12 +1,10 @@ import 'package:flutter/foundation.dart'; class YahooAuctionsItem { - String id; String name; int price; YahooAuctionsItem({ - @required this.id, @required this.name, @required this.price }); diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 77c7e59..df01c43 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -52,13 +52,23 @@ class _MainPageState extends State { padding: EdgeInsets.all(8.0), separatorBuilder: (context, i) => Divider(), 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()] - )), - ), + itemBuilder: (context, i) { + String key = listings.items.keys.elementAt(i); + return ListTile( + title: Text(listings.items[key].name), + subtitle: Text(sprintf( + "¥%d (≈\$%2.2f)", + [listings.items[key].price, listings.items[key].getLocalPrice()] + )), + onTap: () { + Navigator.pushNamed( + context, + '/view_listing', + arguments: key + ); + } + ); + } ); } } diff --git a/lib/pages/splash.dart b/lib/pages/splash.dart index a9c6fc8..cff9d46 100644 --- a/lib/pages/splash.dart +++ b/lib/pages/splash.dart @@ -18,8 +18,9 @@ class _RouteSplashState extends State { 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", + listings.add( + "k" + (_rng.nextInt(500000) + 100000).toString(), + YahooAuctionsItem( name: names[_rng.nextInt(names.length)], price: _rng.nextInt(5000) + 500 )); diff --git a/lib/pages/view_listing.dart b/lib/pages/view_listing.dart new file mode 100644 index 0000000..9c32821 --- /dev/null +++ b/lib/pages/view_listing.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; + +class RouteViewListing extends StatefulWidget { + @override + _RouteViewListingState createState() => _RouteViewListingState(); +} + +class _RouteViewListingState extends State { + @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") + ) + ] + ) + ); + } +}