Compare commits
2 commits
0969b41bc3
...
395778a623
Author | SHA1 | Date | |
---|---|---|---|
395778a623 | |||
55e8c828a4 |
6 changed files with 79 additions and 31 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,11 +31,12 @@ void main() {
|
|||
routes: {
|
||||
'/': (context) => RouteHome(),
|
||||
'/splash': (context) => RouteSplash(),
|
||||
'/view_listing': (context) => RouteViewListing(),
|
||||
},
|
||||
|
||||
title: "Buypeeb Mobile",
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.orange,
|
||||
primarySwatch: Colors.pink,
|
||||
),
|
||||
)
|
||||
),
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
|
@ -9,13 +9,7 @@ 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(),
|
||||
);
|
||||
return MainPage();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,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
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,26 +10,28 @@ class RouteSplash extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _RouteSplashState extends State<RouteSplash> {
|
||||
bool _ready = false;
|
||||
|
||||
_loadUserSettings() async {
|
||||
// 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
|
||||
var listings = context.read<UserListings>();
|
||||
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
|
||||
));
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_ready = true;
|
||||
Navigator.pushNamed(context, '/');
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/',
|
||||
(Route<dynamic> route) => false,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -43,7 +45,22 @@ class _RouteSplashState extends State<RouteSplash> {
|
|||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
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(),
|
||||
]
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
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