added a page to view individual listings, switched from list to map
This commit is contained in:
parent
55e8c828a4
commit
395778a623
6 changed files with 55 additions and 17 deletions
|
@ -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",
|
||||
|
|
|
@ -3,17 +3,18 @@ import 'package:buyeeb_mobile/models/yahoo_auctions_item.dart';
|
|||
import 'package:flutter/foundation.dart';
|
||||
|
||||
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) {
|
||||
_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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
|
@ -52,13 +52,23 @@ class _MainPageState extends State<MainPage> {
|
|||
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
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,9 @@ class _RouteSplashState extends State<RouteSplash> {
|
|||
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
|
||||
));
|
||||
|
|
26
lib/pages/view_listing.dart
Normal file
26
lib/pages/view_listing.dart
Normal 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")
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue