Skip to content

Commit

Permalink
Add notifications for order packed
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwat1998 committed Jun 29, 2020
1 parent 09d628b commit aadf7d5
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/screens/home/drawer_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DrawerList extends StatelessWidget {
),
),
Container(
child: Text('$name',
child: Text('$userName',
style: TextStyle(fontWeight: FontWeight.bold, fontStyle: FontStyle.italic,
color: backgroundColor,
fontSize: 25,
Expand Down
79 changes: 61 additions & 18 deletions lib/screens/home/home.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:geolocator/geolocator.dart';
Expand Down Expand Up @@ -27,12 +28,43 @@ class Home extends StatefulWidget {
class _HomeState extends State<Home> {
final AuthService _auth = AuthService();

final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();

_register() {
_firebaseMessaging.getToken().then((token) {
print(token+"end");
userToken = token;
DatabaseService(uid: userUid).updateTokenData(userToken);
});
}

@override
void initState() {
// TODO: implement initState
super.initState();
getMessage();
}

void getMessage(){
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on message $message');
//setState(() => _message = message["notification"]["title"]);
}, onResume: (Map<String, dynamic> message) async {
print('on resume $message');
//setState(() => _message = message["notification"]["title"]);
}, onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
//setState(() => _message = message["notification"]["title"]);
});
}


@override
Widget build(BuildContext context) {

User user = Provider.of<User>(context);
userUid = user.uid;
DatabaseService(uid: userUid).getUserDetails();

void _showSettingsPanel() {
showModalBottomSheet(context: context, builder: (context) {
Expand Down Expand Up @@ -120,24 +152,35 @@ class _HomeState extends State<Home> {
color: backgroundColor,
child: widget.showVendors? StreamProvider<List<Vendor>>.value(
value: DatabaseService().vendors,
child:FutureBuilder(
future: Geolocator().getCurrentPosition(
desiredAccuracy: LocationAccuracy.best),
builder: (BuildContext context, AsyncSnapshot<Position> snapshot){
child:FutureBuilder<bool>(
future: DatabaseService(uid: userUid).getUserDetails(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
print("1");
if(snapshot.data == null) return Loading();
Position pos = snapshot.data;
userLatitude = pos.latitude;
userLongitude = pos.longitude;
print(userLatitude+userLongitude);
currentVendor = '';
return VendorList(
selectVendor: (){
setState(() {
print("yes it works");
widget.showVendors = false;
});
},
);},
print(snapshot.data);
print("works here");
_register();
print('yes');
return FutureBuilder(
future: Geolocator().getCurrentPosition(
desiredAccuracy: LocationAccuracy.best),
builder: (BuildContext context, AsyncSnapshot<Position> snapshot){
if(snapshot.data == null) return Loading();
Position pos = snapshot.data;
userLatitude = pos.latitude;
userLongitude = pos.longitude;
print(userLatitude+userLongitude);
currentVendor = '';
return VendorList(
selectVendor: (){
setState(() {
print("yes it works");
widget.showVendors = false;
});
},
);},
);
}
),
):StreamProvider<List<Item>>.value(
value: DatabaseService().items,
Expand Down
12 changes: 11 additions & 1 deletion lib/services/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DatabaseService {
}).toList();
}

Future<void> getUserDetails() async{
Future<bool> getUserDetails() async{
loadCart();
return await userCollection.document(uid).get().then((value) {
userUid = uid;
Expand All @@ -60,6 +60,7 @@ class DatabaseService {
userPhoneNo = value.data['phone'];
userCartVendor = value.data['cartVendor'];
userCartVal = value.data['cartVal'];
return true;
});
}

Expand Down Expand Up @@ -101,8 +102,17 @@ class DatabaseService {
'phone': userData.phoneNo,
'cartVendor': userData.cartVendor,
'cartVal': userData.cartVal,
'token': userToken,
});
}

Future<void> updateTokenData(String token) async {
var ref = userCollection.document(uid);
print(ref.path);
return await ref.updateData({'token': token}).then((value) => print("token sent"));
}


// brew list from snapshot
List<Item> _itemListFromSnapshot(QuerySnapshot snapshot) {
return snapshot.documents.map((doc){
Expand Down
1 change: 1 addition & 0 deletions lib/shared/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ String userAddr2 = '';
String userPhoneNo = '';
String userCartVendor = '';
double userCartVal = 0.0;
String userToken = '';
FirebaseUser firebaseUser;
double userLatitude = 0.0;
double userLongitude = 0.0;
Expand Down
16 changes: 15 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ packages:
source: hosted
version: "0.1.3+1"
firebase_core:
dependency: transitive
dependency: "direct main"
description:
name: firebase_core
url: "https://pub.dartlang.org"
Expand All @@ -141,6 +141,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1+2"
firebase_messaging:
dependency: "direct main"
description:
name: firebase_messaging
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.16"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -275,6 +282,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
platform_detect:
dependency: transitive
description:
Expand Down
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
version: 1.0.1+1

environment:
sdk: ">=2.7.0 <3.0.0"
Expand All @@ -37,6 +37,8 @@ dependencies:
shared_preferences: ^0.5.7+3
flutter_rating_bar: ^3.0.1+1
geolocator: ^5.3.2+2
firebase_messaging: ^6.0.16
firebase_core: ^0.4.5
url_launcher: ^5.4.11
flutter_launcher_icons: ^0.7.5

Expand Down

0 comments on commit aadf7d5

Please sign in to comment.