Compare commits

..

No commits in common. "395778a6239c50ded848d52b16b334fa3cfe37c4" and "0969b41bc3c2bc7a50e16da8a5542d4c9f72beeb" have entirely different histories.

6 changed files with 31 additions and 79 deletions

View file

@ -17,7 +17,6 @@
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';
@ -31,12 +30,11 @@ 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.pink, primarySwatch: Colors.orange,
), ),
) )
), ),

View file

@ -3,18 +3,17 @@ 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 = {};
UnmodifiableMapView<String, YahooAuctionsItem> get items => UnmodifiableMapView(_items); UnmodifiableListView<YahooAuctionsItem> get items => UnmodifiableListView(_items);
void add (String key, YahooAuctionsItem item) { void add (YahooAuctionsItem item) {
_items[key] = item; _items.add(item);
notifyListeners(); notifyListeners();
} }
void remove(String key) { void remove(YahooAuctionsItem item) {
_items.remove(key); _items.remove(item);
notifyListeners(); notifyListeners();
} }

View file

@ -1,10 +1,12 @@
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,7 +9,13 @@ 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 MainPage(); return MaterialApp(
title: "Buypeeb",
theme: ThemeData(
primarySwatch: Colors.orange,
),
home: MainPage(),
);
} }
} }
@ -52,23 +58,13 @@ 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) { itemBuilder: (context, i) => ListTile(
String key = listings.items.keys.elementAt(i); title: Text(listings.items[i].name),
return ListTile( subtitle: Text(sprintf(
title: Text(listings.items[key].name), "¥%d (≈\$%2.2f)",
subtitle: Text(sprintf( [listings.items[i].price, listings.items[i].getLocalPrice()]
"¥%d (≈\$%2.2f)", )),
[listings.items[key].price, listings.items[key].getLocalPrice()] ),
)),
onTap: () {
Navigator.pushNamed(
context,
'/view_listing',
arguments: key
);
}
);
}
); );
} }
} }

View file

@ -10,28 +10,26 @@ 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: 2)); await Future.delayed(Duration(seconds: 1));
// 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( listings.add(YahooAuctionsItem(
"k" + (_rng.nextInt(500000) + 100000).toString(), id: "Henlo",
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(() {
Navigator.pushNamedAndRemoveUntil( _ready = true;
context, Navigator.pushNamed(context, '/');
'/',
(Route<dynamic> route) => false,
);
}); });
} }
@ -45,22 +43,7 @@ class _RouteSplashState extends State<RouteSplash> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: Center( body: Center(
child: Column( child: CircularProgressIndicator(),
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

@ -1,26 +0,0 @@
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")
)
]
)
);
}
}