8-15/3
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
@@ -7,8 +8,11 @@ import 'package:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/links.dart';
|
||||
import 'package:ride/controller/functions/crud.dart';
|
||||
import 'package:ride/main.dart';
|
||||
import 'package:ride/views/auth/verify_email_page.dart';
|
||||
import 'package:ride/views/home/map_page.dart';
|
||||
|
||||
import '../firebase/firbase_messge.dart';
|
||||
|
||||
class LoginController extends GetxController {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
TextEditingController emailController = TextEditingController();
|
||||
@@ -46,35 +50,57 @@ class LoginController extends GetxController {
|
||||
'phone': phoneController.text,
|
||||
'password': passwordController.text
|
||||
});
|
||||
|
||||
var jsonDecoeded = jsonDecode(res);
|
||||
// print(jsonDecoeded);
|
||||
if (jsonDecoeded.isNotEmpty) {
|
||||
if (jsonDecoeded['status'] == 'success') {
|
||||
if (jsonDecoeded['data'][0]['verified'] == '1') {
|
||||
box.write(BoxName.pasengerID, jsonDecoeded['data'][0]['id']);
|
||||
box.write(BoxName.email, jsonDecoeded['data'][0]['email']);
|
||||
box.write(BoxName.phone, jsonDecoeded['data'][0]['phone']);
|
||||
Get.offAll(() => MapPage());
|
||||
if (res == 'Failure') {
|
||||
isloading = false;
|
||||
update();
|
||||
Get.snackbar('Failure', '', backgroundColor: Colors.red);
|
||||
} else {
|
||||
var jsonDecoeded = jsonDecode(res);
|
||||
// print(jsonDecoeded);
|
||||
if (jsonDecoeded.isNotEmpty) {
|
||||
if (jsonDecoeded['status'] == 'success') {
|
||||
print(jsonDecoeded['data'][0]['verified']);
|
||||
if (jsonDecoeded['data'][0]['verified'] == 1) {
|
||||
box.write(BoxName.pasengerID, jsonDecoeded['data'][0]['id']);
|
||||
box.write(BoxName.email, jsonDecoeded['data'][0]['email']);
|
||||
box.write(BoxName.phone, jsonDecoeded['data'][0]['phone']);
|
||||
Get.offAll(() => MapPage());
|
||||
isloading = false;
|
||||
update();
|
||||
print(box.read(BoxName.pasengerID).toString());
|
||||
print(box.read(BoxName.tokenFCM));
|
||||
await CRUD().post(link: AppLink.addTokens, payload: {
|
||||
'token': box.read(BoxName.tokenFCM),
|
||||
'passengerID': box.read(BoxName.pasengerID).toString()
|
||||
}).then((value) => print('cccc'));
|
||||
} else {
|
||||
isloading = false;
|
||||
update();
|
||||
Get.defaultDialog(
|
||||
title: 'You must Verify email !.'.tr,
|
||||
middleText: '',
|
||||
backgroundColor: Colors.yellow[300],
|
||||
onConfirm: () async {
|
||||
int randomNumber = Random().nextInt(100000) + 1;
|
||||
await CRUD().post(link: AppLink.sendVerifyEmail, payload: {
|
||||
'email': emailController.text,
|
||||
'token': randomNumber.toString(),
|
||||
}).then((value) => print(value));
|
||||
Get.to(() => const VerifyEmailPage());
|
||||
},
|
||||
);
|
||||
}
|
||||
} else if (jsonDecoeded['status'] == 'Failure') {
|
||||
Get.snackbar(jsonDecoeded['status'], jsonDecoeded['data'],
|
||||
backgroundColor: Colors.redAccent);
|
||||
isloading = false;
|
||||
update();
|
||||
print(box.read(BoxName.pasengerID).toString());
|
||||
await CRUD().post(link: AppLink.addTokens, payload: {
|
||||
'token': box.read(BoxName.tokenFCM.toString()),
|
||||
'passengerID': box.read(BoxName.pasengerID).toString()
|
||||
}).then((value) => print('cccc'));
|
||||
} else {
|
||||
Get.snackbar('You must Verify email !.'.tr, '',
|
||||
backgroundColor: Colors.yellow[300]);
|
||||
}
|
||||
} else if (jsonDecoeded['status'] == 'Failure') {
|
||||
Get.snackbar(jsonDecoeded['status'], jsonDecoeded['data'],
|
||||
backgroundColor: Colors.redAccent);
|
||||
} else {
|
||||
print('res is null');
|
||||
isloading = false;
|
||||
update();
|
||||
}
|
||||
} else {
|
||||
print('res is null');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +113,7 @@ class LoginController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
FirebasMessagesController().requestPermission();
|
||||
// goToMapPage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,11 +61,10 @@ class RegisterController extends GetxController {
|
||||
'email': emailController.text,
|
||||
'token': verfyCode.text,
|
||||
});
|
||||
var jsondecod = jsonDecode(res);
|
||||
|
||||
if (jsondecod['status'] == 'success') {
|
||||
Get.offAll(() => const MapPage());
|
||||
}
|
||||
// if (jsondecod['status'] == 'success') {
|
||||
Get.offAll(() => const MapPage());
|
||||
// }
|
||||
}
|
||||
|
||||
void register() async {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:ride/constant/colors.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/credential.dart';
|
||||
@@ -29,17 +31,39 @@ class FirebasMessagesController extends GetxController {
|
||||
await FirebaseMessaging.instance.getNotificationSettings();
|
||||
print('------noti======');
|
||||
print(notificationSettings!.authorizationStatus.toString());
|
||||
// if (notificationSettings?.authorizationStatus.toString() ==
|
||||
// 'AuthorizationStatus.denied') {
|
||||
// await Get.defaultDialog(
|
||||
// title: 'AuthorizationStatus',
|
||||
// content: TextButton(
|
||||
// onPressed: () {
|
||||
// requestPermission();
|
||||
// },
|
||||
// child: Text(
|
||||
// "Text Button",
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
update();
|
||||
}
|
||||
|
||||
void requestPermission() async {
|
||||
Future checkAndRequestPermission() async {
|
||||
if (notificationSettings!.authorizationStatus ==
|
||||
AuthorizationStatus.denied) {
|
||||
await requestPermission();
|
||||
}
|
||||
}
|
||||
|
||||
Future requestPermission() async {
|
||||
// Check if the platform is Android
|
||||
if (Platform.isAndroid) {
|
||||
// Request permission for Android
|
||||
fcmToken.requestPermission().then((value) {
|
||||
if (value!.authorizationStatus == AuthorizationStatus.denied) {
|
||||
if (value.authorizationStatus == AuthorizationStatus.denied) {
|
||||
print('dddddddddddddddddddddd');
|
||||
}
|
||||
print(value.authorizationStatus);
|
||||
});
|
||||
} else {
|
||||
// Request permission for iOS
|
||||
@@ -86,8 +110,8 @@ class FirebasMessagesController extends GetxController {
|
||||
// final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await fcmToken.getToken().then(
|
||||
(token) {
|
||||
// print(token);/
|
||||
box.write(BoxName.tokenFCM, token);
|
||||
print(box.read(BoxName.tokenFCM).toString());
|
||||
},
|
||||
);
|
||||
FirebaseMessaging.onMessage.listen((event) {
|
||||
@@ -95,8 +119,8 @@ class FirebasMessagesController extends GetxController {
|
||||
'onMessage: ${event.notification!.title} ${event.notification!.body}');
|
||||
if (Get.currentRoute == '/') {
|
||||
// If the app is in the foreground, show a dialog to the user
|
||||
if (event.notification!.title.toString().contains('reef')) {
|
||||
// Get.snackbar('reeffff', 'message');
|
||||
if (event.notification!.title.toString().contains('ride')) {
|
||||
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
|
||||
} else if (event.notification!.title.toString().contains('انذار')) {
|
||||
// Get.to(() => const ProfilePage());
|
||||
} else if (event.notification!.title
|
||||
@@ -112,8 +136,8 @@ class FirebasMessagesController extends GetxController {
|
||||
if (notification != null && android != null) {
|
||||
print(
|
||||
'onMessageOpenedApp: ${notification.title} ${notification.body}');
|
||||
if (event.notification!.title.toString().contains('reef')) {
|
||||
// Get.snackbar('reef', '');
|
||||
if (event.notification!.title.toString().contains('ride')) {
|
||||
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
|
||||
// SendGpsNow().getSiteNotification();
|
||||
} else if (event.notification!.title.toString().contains('انذار')) {
|
||||
// Get.to(() => const ProfilePage());
|
||||
@@ -134,8 +158,8 @@ class FirebasMessagesController extends GetxController {
|
||||
if (notification != null) {
|
||||
print('onMessageOpenedApp: ${notification.title} ${notification.body}');
|
||||
|
||||
if (event.notification!.title.toString().contains('reef')) {
|
||||
// Get.snackbar('reef', '');
|
||||
if (event.notification!.title.toString().contains('ride')) {
|
||||
Get.snackbar('ride', 'message', backgroundColor: AppColor.redColor);
|
||||
// SendGpsNow().getSiteNotification();
|
||||
} else if (event.notification!.title.toString().contains('انذار')) {
|
||||
// Get.to(() => const ProfilePage());
|
||||
|
||||
@@ -21,7 +21,7 @@ class CRUD {
|
||||
'Basic ${base64Encode(utf8.encode(AppCredintials.basicAuthCredentials))}',
|
||||
},
|
||||
);
|
||||
// print("--------------" + response.request.toString());
|
||||
// print("--------------" + response.body.toString());
|
||||
if (response.statusCode == 200) {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (jsonData['status'] == 'success') {
|
||||
@@ -49,8 +49,8 @@ class CRUD {
|
||||
},
|
||||
);
|
||||
print(response.request);
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (jsonData['status'] == 'success') {
|
||||
Get.snackbar(
|
||||
jsonData['status'],
|
||||
@@ -60,7 +60,7 @@ class CRUD {
|
||||
return response.body;
|
||||
}
|
||||
}
|
||||
// return (response.body);
|
||||
return (jsonData['status']);
|
||||
}
|
||||
|
||||
Future<dynamic> getGoogleApi({
|
||||
|
||||
47
lib/controller/functions/log_out.dart
Normal file
47
lib/controller/functions/log_out.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/basic.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/colors.dart';
|
||||
import 'package:ride/main.dart';
|
||||
import 'package:ride/views/lang/languages.dart';
|
||||
import 'package:ride/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../constant/style.dart';
|
||||
|
||||
class LogOut {
|
||||
Future logOut() async {
|
||||
Get.defaultDialog(
|
||||
title: 'Are you Sure to LogOut?'.tr,
|
||||
content: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
MyElevatedButton(
|
||||
title: 'Cancel'.tr,
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(AppColor.redColor),
|
||||
),
|
||||
onPressed: () {
|
||||
// box.remove(BoxName.agreeTerms);
|
||||
box.remove(BoxName.driverID);
|
||||
box.remove(BoxName.email);
|
||||
box.remove(BoxName.lang);
|
||||
box.remove(BoxName.name);
|
||||
box.remove(BoxName.pasengerID);
|
||||
box.remove(BoxName.phone);
|
||||
box.remove(BoxName.tokenFCM);
|
||||
box.remove(BoxName.tokens);
|
||||
Get.offAll(const Language());
|
||||
},
|
||||
child: Text(
|
||||
'Sign Out'.tr,
|
||||
style:
|
||||
AppStyle.title.copyWith(color: AppColor.secondaryColor),
|
||||
))
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import 'package:ride/controller/functions/crud.dart';
|
||||
import 'package:ride/views/home/map_widget.dart/buttom_sheet_map_show.dart';
|
||||
|
||||
import '../../models/model/locations.dart';
|
||||
import '../firebase/firbase_messge.dart';
|
||||
|
||||
class MapController extends GetxController {
|
||||
bool isloading = true;
|
||||
@@ -429,6 +430,7 @@ class MapController extends GetxController {
|
||||
void onInit() async {
|
||||
// getPolyLine();
|
||||
// getMap();
|
||||
FirebasMessagesController().requestPermission();
|
||||
await getLocation();
|
||||
await getCarsLocationByPassenger();
|
||||
addCustomPicker();
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:get/get.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../main.dart';
|
||||
import '../firebase/firbase_messge.dart';
|
||||
import '../themes/themes.dart';
|
||||
|
||||
class LocaleController extends GetxController {
|
||||
@@ -21,6 +22,7 @@ class LocaleController extends GetxController {
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
FirebasMessagesController().requestPermission();
|
||||
if (box.read(BoxName.lang) == "ar") {
|
||||
language = const Locale("ar");
|
||||
appTheme = themeArabic;
|
||||
|
||||
Reference in New Issue
Block a user