From 1db04f14479673f182fa7ae00cc13e938c895854 Mon Sep 17 00:00:00 2001 From: Rohan Dhesikan Date: Sun, 2 Dec 2018 16:27:38 -0500 Subject: [PATCH] new changes --- lib/Checkout.dart | 77 ++++++++++++++++++++++++ lib/StoreDetails.dart | 136 ++++++++++++++++++++++++++++++++++++++++++ lib/StoreList.dart | 15 ++++- lib/global.dart | 16 +++-- lib/main.dart | 3 + 5 files changed, 239 insertions(+), 8 deletions(-) create mode 100644 lib/Checkout.dart create mode 100644 lib/StoreDetails.dart diff --git a/lib/Checkout.dart b/lib/Checkout.dart new file mode 100644 index 0000000..21c5f38 --- /dev/null +++ b/lib/Checkout.dart @@ -0,0 +1,77 @@ + +import 'package:flutter/material.dart'; +import 'global.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; +import 'global.dart'; + +class Checkout extends StatefulWidget { + final List prices; + final List items; + final List nums; + final String title; + final int total; + + Checkout({Key key, this.title, @required this.items, @required this.prices, @required this.nums, @required this.total}) : super(key: key); + + + @override + CheckoutState createState() => CheckoutState(); +} + +class CheckoutState extends State { + + List j = new List(); + + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: new Scaffold( + appBar: AppBar( + title: const Text('Basic AppBar')), + body: new SafeArea( + + child: Column( + + mainAxisSize: MainAxisSize.max, + children: [ + + new ListView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: widget.items.length, + itemBuilder: (context, index) { + return Card( + child: + new Container( + height: 50.0, + child: new Row( + children: [ + Text(widget.nums[index].toString()+" "+ widget.items[index]+": "+widget.prices[index].toString()+" dollars each"), + + ], + ) + ) + ); + }, + ), + new FlatButton( + onPressed: (){ + }, + color: Colors.blue, + child: Text( + widget.total.toString())) + ], + ), + ),) + , + ); + } + + +} diff --git a/lib/StoreDetails.dart b/lib/StoreDetails.dart new file mode 100644 index 0000000..682f0c0 --- /dev/null +++ b/lib/StoreDetails.dart @@ -0,0 +1,136 @@ + +import 'package:flutter/material.dart'; +import 'global.dart'; +import 'Checkout.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; +import 'global.dart'; + +class StoreDetails extends StatefulWidget { + final Store ste; + final String title; + final int length; + + StoreDetails({Key key, this.title, @required this.ste, @required this.length}) : super(key: key); + + + @override + StoreDetailsState createState() => StoreDetailsState(); +} + +class StoreDetailsState extends State { + + List j = new List(); + int total = 0; + + + @override + Widget build(BuildContext context) { + while(j.length < widget.ste.menu.length){ + j.add(0); + } + print(widget.ste); + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: new Scaffold( + appBar: AppBar( + title: const Text('Basic AppBar')), + body: new SafeArea( + + child: Column( + + mainAxisSize: MainAxisSize.max, + children: [ + + new Card( + child: Container( + child: new Column( + children: [ + new Text ((widget.ste.name), + style: new TextStyle (fontWeight: FontWeight.bold),), + new Text (widget.ste.type), + new Text (widget.ste.price), + new Text (widget.ste.location), + ], + ), + width: 100.0, + color: Colors.blue + ) + ), + new ListView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: widget.ste.menu.length, + itemBuilder: (context, index) { + return Card( + child: new Row( + children: [ + Text(widget.ste.menu[index]+": "+widget.ste.prices[index].toString()+" dollars"), + + + IconButton( + alignment: Alignment.centerRight, + icon: Icon(Icons.remove_circle), + onPressed: () { + setState(() { + if(j[index]==null || j[index] == 0){ + j[index] = 0; + + } + else { + j[index] = j[index]-1; + total = total - widget.ste.prices[index]; + } + }); + setState(() { + + }); + }, + ), + Text(j[index].toString()), + + IconButton( + alignment: Alignment.centerRight, + icon: Icon(Icons.add_circle), + onPressed: () { + setState(() { + print(j.length); + if(j[index]==null){ + j[index] = 1; + total = total + widget.ste.prices[index]; + } + else { + j[index] = j[index]+1; + total = total + widget.ste.prices[index]; + } + }); + }, + ), + + ], + ) + ); + }, + ), + new FlatButton( + onPressed: (){ + Navigator.push( + context, + MaterialPageRoute(builder: (context) => Checkout(items: widget.ste.menu, nums: j, prices: widget.ste.prices, total:total)), + ); }, + color: Colors.blue, + child: Text( + total.toString() + )) + ], + ), + ),) + , + ); + } + + +} diff --git a/lib/StoreList.dart b/lib/StoreList.dart index d7fb9ab..2ad77d6 100644 --- a/lib/StoreList.dart +++ b/lib/StoreList.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'global.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; +import 'StoreDetails.dart'; Future> fetchPost() async { final response = @@ -57,8 +58,15 @@ class StoreListState extends State { itemCount: listNum, itemBuilder: (context, index) { return new Container ( + child: new GestureDetector( + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) => StoreDetails(ste: snapshot.data[index], length: snapshot.data.length,)), + ); + }, child: new Card ( - color: Colors.greenAccent, + color: Colors.blue, child: Column( mainAxisSize: MainAxisSize.min, @@ -67,9 +75,9 @@ class StoreListState extends State { new Text ((snapshot.data[index].name), style: new TextStyle (fontWeight: FontWeight.bold),), - new Text (snapshot.data[index].time), + new Text (snapshot.data[index].type), new Text (snapshot.data[index].price), - new Text ("300 feet"), + new Text (snapshot.data[index].location), /*FlatButton( color: Colors.blue, child: new Text ("Go"), @@ -82,6 +90,7 @@ class StoreListState extends State { ] ), + ) ), alignment: Alignment.center); } ); diff --git a/lib/global.dart b/lib/global.dart index be6e4d6..22f4912 100644 --- a/lib/global.dart +++ b/lib/global.dart @@ -8,13 +8,16 @@ int listNum = 0; class Store { String name; - String time; + String type; String price; - String distance; + String location; + String id; + List menu; + List prices; - Store({this.name, this.time, this.price, this.distance}); + Store({this.name, this.type, this.price, this.location, this.id, this.menu, this.prices}); factory Store.fromJson(Map json) { int len = json['length']; @@ -23,9 +26,12 @@ class Store { for(int i = 0; i runApp(MyApp()); class MyApp extends StatelessWidget { @@ -12,6 +13,8 @@ class MyApp extends StatelessWidget { primarySwatch: Colors.blue, ), home: new Scaffold( + appBar: AppBar( + title: const Text('Fastplate')), body: MyHomePage(title: 'Dining places'), )