BASE: Switch From EasyLocalization To GetX Localization.

This commit is contained in:
2025-12-04 16:56:39 +05:00
parent 157545f1c0
commit bf1d07a048
218 changed files with 2535 additions and 2313 deletions

View File

@@ -9,25 +9,51 @@ Future<void> firebaseMessageBackgroundHandle(RemoteMessage message) async {
}
class NotificationService {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
Future<void> initInfo() async {
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(alert: true, badge: true, sound: true);
var request = await FirebaseMessaging.instance.requestPermission(alert: true, announcement: false, badge: true, carPlay: false, criticalAlert: false, provisional: false, sound: true);
await FirebaseMessaging.instance
.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
var request = await FirebaseMessaging.instance.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
if (request.authorizationStatus == AuthorizationStatus.authorized || request.authorizationStatus == AuthorizationStatus.provisional) {
const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/ic_launcher');
if (request.authorizationStatus == AuthorizationStatus.authorized ||
request.authorizationStatus == AuthorizationStatus.provisional) {
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher');
var iosInitializationSettings = const DarwinInitializationSettings();
final InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid, iOS: iosInitializationSettings);
await flutterLocalNotificationsPlugin.initialize(initializationSettings, onDidReceiveNotificationResponse: (payload) {});
final InitializationSettings initializationSettings =
InitializationSettings(
android: initializationSettingsAndroid,
iOS: iosInitializationSettings,
);
await flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse: (payload) {},
);
setupInteractedMessage();
}
}
Future<void> setupInteractedMessage() async {
RemoteMessage? initialMessage = await FirebaseMessaging.instance.getInitialMessage();
RemoteMessage? initialMessage =
await FirebaseMessaging.instance.getInitialMessage();
if (initialMessage != null) {
FirebaseMessaging.onBackgroundMessage((message) => firebaseMessageBackgroundHandle(message));
FirebaseMessaging.onBackgroundMessage(
(message) => firebaseMessageBackgroundHandle(message),
);
}
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
@@ -103,18 +129,38 @@ class NotificationService {
log('Got a message whilst in the foreground!');
log('Message data: ${message.notification!.body.toString()}');
try {
AndroidNotificationChannel channel = const AndroidNotificationChannel('0', 'eMart customer', description: 'Show eMart Notification', importance: Importance.max);
AndroidNotificationDetails notificationDetails = AndroidNotificationDetails(
channel.id,
channel.name,
channelDescription: 'your channel Description',
importance: Importance.high,
priority: Priority.high,
ticker: 'ticker',
AndroidNotificationChannel channel = const AndroidNotificationChannel(
'0',
'eMart customer',
description: 'Show eMart Notification',
importance: Importance.max,
);
AndroidNotificationDetails notificationDetails =
AndroidNotificationDetails(
channel.id,
channel.name,
channelDescription: 'your channel Description',
importance: Importance.high,
priority: Priority.high,
ticker: 'ticker',
);
const DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(
presentAlert: true,
presentBadge: true,
presentSound: true,
);
NotificationDetails notificationDetailsBoth = NotificationDetails(
android: notificationDetails,
iOS: darwinNotificationDetails,
);
await FlutterLocalNotificationsPlugin().show(
0,
message.notification!.title,
message.notification!.body,
notificationDetailsBoth,
payload: jsonEncode(message.data),
);
const DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails(presentAlert: true, presentBadge: true, presentSound: true);
NotificationDetails notificationDetailsBoth = NotificationDetails(android: notificationDetails, iOS: darwinNotificationDetails);
await FlutterLocalNotificationsPlugin().show(0, message.notification!.title, message.notification!.body, notificationDetailsBoth, payload: jsonEncode(message.data));
} on Exception catch (e) {
log(e.toString());
}

View File

@@ -1,7 +1,8 @@
import 'package:customer/constant/constant.dart';
import 'package:customer/widget/place_picker/selected_location_model.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:map_launcher/map_launcher.dart';
import '../themes/show_toast_dialog.dart';
@@ -37,7 +38,9 @@ class Utils {
if (permission == LocationPermission.deniedForever) {
// Permissions are denied forever, handle appropriately.
return Future.error('Location permissions are permanently denied, we cannot request permissions.');
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.',
);
}
// When we reach here, permissions are granted and we can
@@ -45,12 +48,16 @@ class Utils {
return await Geolocator.getCurrentPosition();
}
static Future<String> getAddressFromCoordinates(double lat, double lng) async {
static Future<String> getAddressFromCoordinates(
double lat,
double lng,
) async {
try {
List<Placemark> placemarks = await placemarkFromCoordinates(lat, lng);
if (placemarks.isNotEmpty) {
Placemark place = placemarks.first;
String address = "${place.name ?? ''}, ${place.subLocality ?? ''}, ${place.locality ?? ''}, ${place.administrativeArea ?? ''}, ${place.country ?? ''}";
String address =
"${place.name ?? ''}, ${place.subLocality ?? ''}, ${place.locality ?? ''}, ${place.administrativeArea ?? ''}, ${place.country ?? ''}";
return address;
}
return "Unknown location";
@@ -59,67 +66,122 @@ class Utils {
}
}
static Future<void> redirectMap({required String name, required double latitude, required double longLatitude}) async {
static Future<void> redirectMap({
required String name,
required double latitude,
required double longLatitude,
}) async {
if (Constant.mapType == "google") {
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.google);
if (isAvailable == true) {
await MapLauncher.showDirections(mapType: MapType.google, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
await MapLauncher.showDirections(
mapType: MapType.google,
directionsMode: DirectionsMode.driving,
destinationTitle: name,
destination: Coords(latitude, longLatitude),
);
} else {
ShowToastDialog.showToast("Google map is not installed".tr());
ShowToastDialog.showToast("Google map is not installed".tr);
}
} else if (Constant.mapType == "googleGo") {
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.googleGo);
if (isAvailable == true) {
await MapLauncher.showDirections(mapType: MapType.googleGo, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
await MapLauncher.showDirections(
mapType: MapType.googleGo,
directionsMode: DirectionsMode.driving,
destinationTitle: name,
destination: Coords(latitude, longLatitude),
);
} else {
ShowToastDialog.showToast("Google Go map is not installed".tr());
ShowToastDialog.showToast("Google Go map is not installed".tr);
}
} else if (Constant.mapType == "waze") {
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.waze);
if (isAvailable == true) {
await MapLauncher.showDirections(mapType: MapType.waze, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
await MapLauncher.showDirections(
mapType: MapType.waze,
directionsMode: DirectionsMode.driving,
destinationTitle: name,
destination: Coords(latitude, longLatitude),
);
} else {
ShowToastDialog.showToast("Waze is not installed".tr());
ShowToastDialog.showToast("Waze is not installed".tr);
}
} else if (Constant.mapType == "mapswithme") {
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.mapswithme);
if (isAvailable == true) {
await MapLauncher.showDirections(mapType: MapType.mapswithme, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
await MapLauncher.showDirections(
mapType: MapType.mapswithme,
directionsMode: DirectionsMode.driving,
destinationTitle: name,
destination: Coords(latitude, longLatitude),
);
} else {
ShowToastDialog.showToast("Mapswithme is not installed".tr());
ShowToastDialog.showToast("Mapswithme is not installed".tr);
}
} else if (Constant.mapType == "yandexNavi") {
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.yandexNavi);
if (isAvailable == true) {
await MapLauncher.showDirections(mapType: MapType.yandexNavi, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
await MapLauncher.showDirections(
mapType: MapType.yandexNavi,
directionsMode: DirectionsMode.driving,
destinationTitle: name,
destination: Coords(latitude, longLatitude),
);
} else {
ShowToastDialog.showToast("YandexNavi is not installed".tr());
ShowToastDialog.showToast("YandexNavi is not installed".tr);
}
} else if (Constant.mapType == "yandexMaps") {
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.yandexMaps);
if (isAvailable == true) {
await MapLauncher.showDirections(mapType: MapType.yandexMaps, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
await MapLauncher.showDirections(
mapType: MapType.yandexMaps,
directionsMode: DirectionsMode.driving,
destinationTitle: name,
destination: Coords(latitude, longLatitude),
);
} else {
ShowToastDialog.showToast("yandexMaps map is not installed".tr());
ShowToastDialog.showToast("yandexMaps map is not installed".tr);
}
}
}
static String formatAddress({required SelectedLocationModel selectedLocation}) {
static String formatAddress({
required SelectedLocationModel selectedLocation,
}) {
List<String> parts = [];
if (selectedLocation.address!.name != null && selectedLocation.address!.name!.isNotEmpty) parts.add(selectedLocation.address!.name!);
if (selectedLocation.address!.subThoroughfare != null && selectedLocation.address!.subThoroughfare!.isNotEmpty) parts.add(selectedLocation.address!.subThoroughfare!);
if (selectedLocation.address!.thoroughfare != null && selectedLocation.address!.thoroughfare!.isNotEmpty) parts.add(selectedLocation.address!.thoroughfare!);
if (selectedLocation.address!.subLocality != null && selectedLocation.address!.subLocality!.isNotEmpty) parts.add(selectedLocation.address!.subLocality!);
if (selectedLocation.address!.locality != null && selectedLocation.address!.locality!.isNotEmpty) parts.add(selectedLocation.address!.locality!);
if (selectedLocation.address!.subAdministrativeArea != null && selectedLocation.address!.subAdministrativeArea!.isNotEmpty) {
if (selectedLocation.address!.name != null &&
selectedLocation.address!.name!.isNotEmpty)
parts.add(selectedLocation.address!.name!);
if (selectedLocation.address!.subThoroughfare != null &&
selectedLocation.address!.subThoroughfare!.isNotEmpty)
parts.add(selectedLocation.address!.subThoroughfare!);
if (selectedLocation.address!.thoroughfare != null &&
selectedLocation.address!.thoroughfare!.isNotEmpty)
parts.add(selectedLocation.address!.thoroughfare!);
if (selectedLocation.address!.subLocality != null &&
selectedLocation.address!.subLocality!.isNotEmpty)
parts.add(selectedLocation.address!.subLocality!);
if (selectedLocation.address!.locality != null &&
selectedLocation.address!.locality!.isNotEmpty)
parts.add(selectedLocation.address!.locality!);
if (selectedLocation.address!.subAdministrativeArea != null &&
selectedLocation.address!.subAdministrativeArea!.isNotEmpty) {
parts.add(selectedLocation.address!.subAdministrativeArea!);
}
if (selectedLocation.address!.administrativeArea != null && selectedLocation.address!.administrativeArea!.isNotEmpty) parts.add(selectedLocation.address!.administrativeArea!);
if (selectedLocation.address!.postalCode != null && selectedLocation.address!.postalCode!.isNotEmpty) parts.add(selectedLocation.address!.postalCode!);
if (selectedLocation.address!.country != null && selectedLocation.address!.country!.isNotEmpty) parts.add(selectedLocation.address!.country!);
if (selectedLocation.address!.isoCountryCode != null && selectedLocation.address!.isoCountryCode!.isNotEmpty) parts.add(selectedLocation.address!.isoCountryCode!);
if (selectedLocation.address!.administrativeArea != null &&
selectedLocation.address!.administrativeArea!.isNotEmpty)
parts.add(selectedLocation.address!.administrativeArea!);
if (selectedLocation.address!.postalCode != null &&
selectedLocation.address!.postalCode!.isNotEmpty)
parts.add(selectedLocation.address!.postalCode!);
if (selectedLocation.address!.country != null &&
selectedLocation.address!.country!.isNotEmpty)
parts.add(selectedLocation.address!.country!);
if (selectedLocation.address!.isoCountryCode != null &&
selectedLocation.address!.isoCountryCode!.isNotEmpty)
parts.add(selectedLocation.address!.isoCountryCode!);
return parts.join(', ');
}