9/3/1
This commit is contained in:
@@ -5,6 +5,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:ride/constant/colors.dart';
|
||||
import 'package:ride/constant/style.dart';
|
||||
import 'package:ride/controller/functions/launch.dart';
|
||||
import 'package:ride/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/credential.dart';
|
||||
@@ -84,31 +87,89 @@ class FirebasMessagesController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void getToken() async {
|
||||
await fcmToken.getToken().then((token) {
|
||||
Future getToken() async {
|
||||
fcmToken.getToken().then((token) {
|
||||
box.write(BoxName.tokenFCM, token);
|
||||
print(token);
|
||||
});
|
||||
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
print(
|
||||
'onMessage: ${message.notification!.title} ${message.notification!.body}');
|
||||
if (Get.currentRoute == '/') {
|
||||
// If the app is in the foreground, show a dialog to the user
|
||||
if (message.notification!.title!.contains('ride')) {
|
||||
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
|
||||
}
|
||||
} else {
|
||||
// If the app is in the background or terminated, show a system tray message
|
||||
RemoteNotification? notification = message.notification;
|
||||
AndroidNotification? android = message.notification?.android;
|
||||
if (notification != null && android != null) {
|
||||
print(
|
||||
'onMessageOpenedApp: ${notification.title} ${notification.body}');
|
||||
if (message.notification!.title!.contains('ride')) {
|
||||
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
|
||||
// SendGpsNow().getSiteNotification();
|
||||
}
|
||||
if (message.data.isNotEmpty) {
|
||||
if (message.notification!.title!.contains('Order')) {
|
||||
var myListString = message.data['myList'];
|
||||
var myList = jsonDecode(myListString) as List<dynamic>;
|
||||
Get.defaultDialog(
|
||||
title: message.notification!.title.toString(),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Text(message.notification!.body.toString()),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
String mapUrl =
|
||||
'https://www.google.com/maps/dir/${myList[0]}/${myList[0]}/';
|
||||
print(mapUrl);
|
||||
launchUrl1(mapUrl);
|
||||
},
|
||||
icon: const Icon(Icons.map),
|
||||
label: Text('Rouats of Trip'.tr)),
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'Tatal From Passenger is '.tr +
|
||||
double.parse(myList[2]).toStringAsFixed(2),
|
||||
style: AppStyle.title,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'Tatal For You is '.tr +
|
||||
double.parse(myList[3]).toStringAsFixed(2),
|
||||
style: AppStyle.title,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'Distance is '.tr + myList[4].toString() + ' Minutes'.tr,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'Duration of Trip is '.tr + myList[5].toString(),
|
||||
style: AppStyle.title,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
MyElevatedButton(
|
||||
title: 'Apply Order'.tr,
|
||||
onPressed: () {
|
||||
//TODO save and request to passenger
|
||||
},
|
||||
),
|
||||
MyElevatedButton(
|
||||
title: 'Refuse Order'.tr,
|
||||
onPressed: () {
|
||||
//TODO save and request to passenger and driver log upto 3 per 1 day
|
||||
},
|
||||
kolor: AppColor.redColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -119,8 +180,8 @@ class FirebasMessagesController extends GetxController {
|
||||
RemoteNotification? notification = message.notification;
|
||||
if (notification != null) {
|
||||
print('onMessageOpenedApp: ${notification.title} ${notification.body}');
|
||||
if (message.notification!.title!.contains('ride')) {
|
||||
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
|
||||
if (message.notification!.title!.contains('SEFER')) {
|
||||
Get.snackbar('SEFER', 'message', backgroundColor: AppColor.redColor);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -222,4 +283,31 @@ class FirebasMessagesController extends GetxController {
|
||||
// print('sendNotification() error: $e');
|
||||
// });
|
||||
// }
|
||||
|
||||
void sendNotificationDriverId(String title, body, Strin1, Strin2, Strin3,
|
||||
Strin4, Strin5, Strin6, token) async {
|
||||
http
|
||||
.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'key=${AppCredintials.serverAPI}'
|
||||
},
|
||||
body: jsonEncode({
|
||||
'notification': <String, dynamic>{
|
||||
'title': title,
|
||||
'body': body,
|
||||
'sound': 'true'
|
||||
},
|
||||
'data': {
|
||||
'myList': jsonEncode(
|
||||
[Strin1, Strin2, Strin3, Strin4, Strin5, Strin6]),
|
||||
},
|
||||
'priority': 'high',
|
||||
'to': token,
|
||||
}))
|
||||
.whenComplete(() {})
|
||||
.catchError((e) {
|
||||
print('sendNotification() error: $e');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user