Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan Dhesikan authored and Rohan Dhesikan committed Dec 2, 2018
1 parent e5ca976 commit 1db04f1
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 8 deletions.
77 changes: 77 additions & 0 deletions lib/Checkout.dart
Original file line number Diff line number Diff line change
@@ -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<dynamic> prices;
final List<dynamic> items;
final List<int> 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<Checkout> {

List<int> 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: <Widget>[

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: <Widget>[
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()))
],
),
),)
,
);
}


}
136 changes: 136 additions & 0 deletions lib/StoreDetails.dart
Original file line number Diff line number Diff line change
@@ -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<StoreDetails> {

List<int> 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: <Widget>[

new Card(
child: Container(
child: new Column(
children: <Widget>[
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: <Widget>[
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()
))
],
),
),)
,
);
}


}
15 changes: 12 additions & 3 deletions lib/StoreList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Store>> fetchPost() async {
final response =
Expand Down Expand Up @@ -57,8 +58,15 @@ class StoreListState extends State<StoreList> {
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,

Expand All @@ -67,9 +75,9 @@ class StoreListState extends State<StoreList> {

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"),
Expand All @@ -82,6 +90,7 @@ class StoreListState extends State<StoreList> {
]

),
)
), alignment: Alignment.center);
}
);
Expand Down
16 changes: 11 additions & 5 deletions lib/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ int listNum = 0;

class Store {
String name;
String time;
String type;
String price;
String distance;
String location;
String id;
List<dynamic> menu;
List<dynamic> 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<String, dynamic> json) {
int len = json['length'];
Expand All @@ -23,9 +26,12 @@ class Store {
for(int i = 0; i<len; i++){
list.add(Store(
name: json[i.toString()]['name'],
time: json[i.toString()]['time'],
type: json[i.toString()]['type'],
price: json[i.toString()]['price'],
distance: json[i.toString()]['distance']
location: json[i.toString()]['location'],
id: json[i.toString()]['id'],
menu: json[i.toString()]['menu'],
prices: json[i.toString()]['prices']
));

}
Expand Down
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:fastplate/StoreList.dart';
import 'StoreDetails.dart';
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
Expand All @@ -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'),
)

Expand Down

0 comments on commit 1db04f1

Please sign in to comment.