Initial commit

This commit is contained in:
2025-12-08 23:25:00 +05:00
commit ee5cb4ac1a
851 changed files with 115172 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:driver/constant/constant.dart';
import 'package:driver/themes/responsive.dart';
import 'package:flutter/material.dart';
class NetworkImageWidget extends StatelessWidget {
final String imageUrl;
final double? height;
final double? width;
final Widget? errorWidget;
final BoxFit? fit;
final double? borderRadius;
final Color? color;
const NetworkImageWidget({
super.key,
this.height,
this.width,
this.fit,
required this.imageUrl,
this.borderRadius,
this.errorWidget,
this.color,
});
@override
Widget build(BuildContext context) {
return CachedNetworkImage(
imageUrl: imageUrl,
fit: fit ?? BoxFit.fitWidth,
height: height ?? Responsive.height(8, context),
width: width ?? Responsive.width(15, context),
color: color,
progressIndicatorBuilder: (context, url, downloadProgress) => Constant.loader(),
errorWidget: (context, url, error) =>
errorWidget ??
Image.network(
Constant.placeHolderImage,
fit: fit ?? BoxFit.fitWidth,
height: height ?? Responsive.height(8, context),
width: width ?? Responsive.width(15, context),
),
);
}
}

View File

@@ -0,0 +1,158 @@
import 'dart:convert';
import 'dart:developer';
import 'package:driver/app/chat_screens/chat_screen.dart';
import 'package:driver/constant/show_toast_dialog.dart';
import 'package:driver/models/user_model.dart';
import 'package:driver/utils/fire_store_utils.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';
Future<void> firebaseMessageBackgroundHandle(RemoteMessage message) async {
log("BackGround Message :: ${message.messageId}");
}
class NotificationService {
final 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,
badge: true,
sound: true,
);
if (request.authorizationStatus == AuthorizationStatus.authorized || request.authorizationStatus == AuthorizationStatus.provisional) {
const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/ic_launcher');
const DarwinInitializationSettings iosInitializationSettings = DarwinInitializationSettings();
final InitializationSettings initializationSettings = InitializationSettings(
android: initializationSettingsAndroid,
iOS: iosInitializationSettings,
);
await flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse: (NotificationResponse response) {
if (response.payload != null) {
_handleNotificationClick(jsonDecode(response.payload!));
}
},
);
setupInteractedMessage();
}
}
Future<void> setupInteractedMessage() async {
// App opened from terminated state
RemoteMessage? initialMessage = await FirebaseMessaging.instance.getInitialMessage();
if (initialMessage != null) {
_handleNotificationClick(initialMessage.data);
}
// App in background and notification tapped
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
_handleNotificationClick(message.data);
});
// App in foreground
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
if (message.notification != null) {
display(message);
}
});
await FirebaseMessaging.instance.subscribeToTopic("driver");
}
static Future<String> getToken() async {
String? token = await FirebaseMessaging.instance.getToken();
return token!;
}
void display(RemoteMessage message) async {
try {
const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails(
'driver_notifications_channel',
'Driver Notifications',
channelDescription: 'App Notifications',
importance: Importance.high,
priority: Priority.high,
ticker: 'ticker',
);
const DarwinNotificationDetails iosDetails = DarwinNotificationDetails(
presentAlert: true,
presentBadge: true,
presentSound: true,
);
const NotificationDetails notificationDetails = NotificationDetails(
android: androidNotificationDetails,
iOS: iosDetails,
);
await flutterLocalNotificationsPlugin.show(
0,
message.notification?.title,
message.notification?.body,
notificationDetails,
payload: jsonEncode(message.data),
);
} catch (e) {
log("Notification display error: $e");
}
}
void _handleNotificationClick(Map<String, dynamic> data) async {
log("Notification Click Data: $data");
if (data["type"] == "chat") {
String? orderId = data["orderId"];
String? restaurantId = data["restaurantId"];
String? customerId = data["customerId"];
String? chatType = data["chatType"] ?? "Driver"; // must match ChatController
if (orderId == null || restaurantId == null || customerId == null) {
log("Invalid chat data in notification.");
return;
}
ShowToastDialog.showLoader("Loading chat...");
// Fetch the profiles
UserModel? customer = await FireStoreUtils.getUserProfile(customerId);
UserModel? restaurantUser = await FireStoreUtils.getUserProfile(restaurantId);
ShowToastDialog.closeLoader();
if (customer == null || restaurantUser == null) {
log("Failed to load user profiles for chat navigation.");
return;
}
// Navigate to ChatScreen with exact arguments
Get.to(() => const ChatScreen(), arguments: {
"customerName": customer.fullName(),
"restaurantName": restaurantUser.fullName(),
"orderId": orderId,
"restaurantId": restaurantUser.id,
"customerId": customer.id,
"customerProfileImage": customer.profilePictureURL ?? "",
"restaurantProfileImage": restaurantUser.profilePictureURL ?? "",
"token": restaurantUser.fcmToken,
"chatType": chatType, // must match ChatController
});
} else {
log("Unhandled notification type: ${data['type']}");
}
}
}

View File

@@ -0,0 +1,61 @@
import 'package:shared_preferences/shared_preferences.dart';
class Preferences {
static const languageCodeKey = "languageCodeKey";
static const isFinishOnBoardingKey = "isFinishOnBoardingKey";
static const foodDeliveryType = "foodDeliveryType";
static const themKey = "themKey";
static const payFastSettings = "payFastSettings";
static const mercadoPago = "MercadoPago";
static const paypalSettings = "paypalSettings";
static const stripeSettings = "stripeSettings";
static const flutterWave = "flutterWave";
static const payStack = "payStack";
static const paytmSettings = "PaytmSettings";
static const walletSettings = "walletSettings";
static const razorpaySettings = "razorpaySettings";
static const midTransSettings = "midTransSettings";
static const orangeMoneySettings = "orangeMoneySettings";
static const xenditSettings = "xenditSettings";
static const codSettings = "CODSettings";
static const orderRingtone = "audioSound";
static late SharedPreferences pref;
static Future<void> initPref() async {
pref = await SharedPreferences.getInstance();
}
static bool getBoolean(String key) {
return pref.getBool(key) ?? false;
}
static Future<void> setBoolean(String key, bool value) async {
await pref.setBool(key, value);
}
static String getString(String key, {String? defaultValue}) {
return pref.getString(key) ?? defaultValue ?? "";
}
static Future<void> setString(String key, String value) async {
await pref.setString(key, value);
}
static int getInt(String key) {
return pref.getInt(key) ?? 0;
}
static Future<void> setInt(String key, int value) async {
await pref.setInt(key, value);
}
static Future<void> clearSharPreference() async {
await pref.clear();
}
static Future<void> clearKeyData(String key) async {
await pref.remove(key);
}
}

119
lib/utils/utils.dart Normal file
View File

@@ -0,0 +1,119 @@
import 'package:driver/constant/constant.dart';
import 'package:driver/constant/show_toast_dialog.dart';
import 'package:geolocator/geolocator.dart';
import 'package:location/location.dart';
import 'package:map_launcher/map_launcher.dart';
class Utils {
static Future<Position?> getCurrentLocation() async {
bool serviceEnabled;
LocationPermission permission;
// Test if location services are enabled.
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
// Location services are not enabled don't continue
// accessing the position and request users of the
// App to enable the location services.
await Location().requestService();
return null;
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
// Permissions are denied, next time you could try
// requesting permissions again (this is also where
// Android's shouldShowRequestPermissionRationale
// returned true. According to Android guidelines
// your App should show an explanatory UI now.
return null;
}
}
if (permission == LocationPermission.deniedForever) {
// Permissions are denied forever, handle appropriately.
return Future.error('Location permissions are permanently denied, we cannot request permissions.');
}
// When we reach here, permissions are granted and we can
// continue accessing the position of the device.
return await Geolocator.getCurrentPosition();
}
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),
);
} else {
ShowToastDialog.showToast("Google map is not installed");
}
} 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),
);
} else {
ShowToastDialog.showToast("Google Go map is not installed");
}
} 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),
);
} else {
ShowToastDialog.showToast("Waze is not installed");
}
} 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),
);
} else {
ShowToastDialog.showToast("Mapswithme is not installed");
}
} 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),
);
} else {
ShowToastDialog.showToast("YandexNavi is not installed");
}
} 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),
);
} else {
ShowToastDialog.showToast("yandexMaps map is not installed");
}
}
}
}