Created
November 12, 2019 15:53
-
-
Save kishea/2c165b1220b5754cab67b602b3259ca7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:provider/provider.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
void main() { | |
Firestore.instance.settings(timestampsInSnapshotsEnabled: true); | |
SharedPreferences.getInstance().then((prefs) { | |
runApp(MakanikaApp(prefs: prefs)); | |
}); | |
} | |
class MakanikaApp extends StatelessWidget { | |
final SharedPreferences prefs; | |
MakanikaApp({this.prefs}); | |
@override | |
Widget build(BuildContext context) { | |
return MultiProvider( | |
providers: [ | |
ChangeNotifierProvider( | |
builder: (_) => MakanikaModel(), | |
), | |
], | |
child: MaterialApp( | |
title: "app 1", | |
theme: ThemeData( | |
primaryColor: Colors.blue, | |
), | |
initialRoute: '/', | |
routes: { | |
'/': (context) => Home(), | |
}, | |
), | |
); | |
} | |
} | |
class MakanikaModel with ChangeNotifier { | |
List<Item> _requestItems = List<Item>(); | |
int _quantity = 0; | |
set quantity(newValue) { | |
_quantity = newValue; | |
notifyListeners(); | |
} | |
set requestItems(newValue) { | |
_requestItems = newValue; | |
notifyListeners(); | |
} | |
//getters | |
List<Item> get requestItems => _requestItems; | |
int get quantity => _quantity; | |
} | |
class Item { | |
int itemQty; | |
final double itemPrice; | |
final double itemDiscount; | |
Item({ | |
this.itemDiscount, | |
this.itemQty, | |
this.itemPrice, | |
}); | |
Map<String, Object> toJson() { | |
return { | |
'itemPrice': itemPrice, | |
'itemQun': itemQty, | |
'itemDiscount': itemDiscount, | |
}; | |
} | |
class Home extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body:Container( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
IconButton( | |
icon: Icon(Icons.remove_circle, | |
color: Colors.amber.shade500), | |
onPressed: () { | |
if (model.quantity > | |
0) { | |
model.quantity--; | |
} | |
}, | |
), | |
new IconButton( | |
icon: Icon(Icons.remove_circle, | |
color: Colors.amber.shade500), | |
onPressed: () { | |
if (itemList[ind].itemQty > | |
0) { | |
Provider.of<MakanikaModel>( | |
context, | |
).requestItems[ind].itemQty--; | |
} | |
}, | |
) | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment