INFRA: Set Up Project.

This commit is contained in:
2025-11-28 11:10:49 +05:00
commit c798279f7d
609 changed files with 77436 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import '../constant/constant.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,
width: width,
color: color,
progressIndicatorBuilder:
(context, url, downloadProgress) => Center(child: SizedBox(height: 24, width: 24, child: CircularProgressIndicator(value: downloadProgress.progress))),
errorWidget: (context, url, error) => errorWidget ?? Image.network(Constant.placeHolderImage, fit: fit ?? BoxFit.fitWidth, height: height, width: width),
);
}
}

View File

@@ -0,0 +1,122 @@
import 'dart:convert';
import 'dart:developer';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
Future<void> firebaseMessageBackgroundHandle(RemoteMessage message) async {
log("BackGround Message :: ${message.messageId}");
// NotificationService.redirectScreen(message);
}
class NotificationService {
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);
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) {});
setupInteractedMessage();
}
}
Future<void> setupInteractedMessage() async {
RemoteMessage? initialMessage = await FirebaseMessaging.instance.getInitialMessage();
if (initialMessage != null) {
FirebaseMessaging.onBackgroundMessage((message) => firebaseMessageBackgroundHandle(message));
}
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
log("::::::::::::onMessage:::::::::::::::::");
if (message.notification != null) {
log(message.notification.toString());
// display(message);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
log("::::::::::::onMessageOpenedApp:::::::::::::::::");
if (message.notification != null) {
log(message.notification.toString());
// redirectScreen(message);
}
});
log("::::::::::::Permission authorized:::::::::::::::::");
await FirebaseMessaging.instance.subscribeToTopic("customer");
}
static Future<String> getToken() async {
String? token = await FirebaseMessaging.instance.getToken();
return token!;
}
// static redirectScreen(RemoteMessage message) async {
// Map<String, dynamic> data = message.data;
// if (data['type'] == "user_chat") {
// String senderId = data['senderId'];
// String receiverId = data['receiverId'];
//
// ShowToastDialog.showLoader("Please wait".tr);
// UserModel? senderUserModel = await FireStoreUtils.getUserProfile(senderId);
// UserModel? receiverUserModel = await FireStoreUtils.getUserProfile(receiverId);
// ShowToastDialog.closeLoader();
// bool isMe = senderUserModel!.id == senderId;
// Get.to(const UserChatScreen(), arguments: {"receiverModel": isMe ? senderUserModel : receiverUserModel});
// } else if (data['type'] == "project_chat") {
// String isSender = data['isSender'];
// String businessId = data['businessId'];
// String projectId = data['projectId'];
//
// ShowToastDialog.showLoader("Please wait".tr);
// PricingRequestModel? pricingRequestModel = await FireStoreUtils.getPricingRequestById(projectId);
// BusinessModel? businessModel = await FireStoreUtils.getBusinessById(businessId);
// UserModel? userModel = await FireStoreUtils.getUserProfile(pricingRequestModel!.userId.toString());
// ShowToastDialog.closeLoader();
// Get.to(ChatScreen(), arguments: {
// "userModel": userModel!,
// "businessModel": businessModel!,
// "projectModel": pricingRequestModel,
// "isSender": isSender == "business" ? "user" : "business",
// });
// } else if (data['type'] == "project_request") {
// String businessId = data['businessId'];
// String projectId = data['projectId'];
// BusinessModel? businessModel = await FireStoreUtils.getBusinessById(businessId);
// Get.to(BusinessProjectListScreen(), arguments: {"businessModel": businessModel});
// } else if (data['type'] == "review") {
// String businessId = data['businessId'];
// BusinessModel? businessModel = await FireStoreUtils.getBusinessById(businessId);
// Get.to(BusinessDetailsScreen(), arguments: {"businessModel": businessModel});
// } else if (data['type'] == "user_follow") {
// String userId = data['userId'];
// ShowToastDialog.showLoader("Please wait");
// UserModel? userModel0 = await FireStoreUtils.getUserProfile(userId.toString());
// ShowToastDialog.closeLoader();
// Get.to(OtherPeopleScreen(), arguments: {"userModel": userModel0});
// }
// }
void display(RemoteMessage message) async {
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',
);
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

@@ -0,0 +1,70 @@
import 'package:shared_preferences/shared_preferences.dart';
class Preferences {
static const isFinishOnBoardingKey = "isFinishOnBoardingKey";
static const isLogin = "isLogin";
static const accessToken = "accessToken";
static const userData = "userData";
static const themKey = "themKey";
static const languageCodeKey = 'languageCodeKey';
static const zipcode = 'zipcode';
static const foodDeliveryType = "foodDeliveryType";
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 codSettings = "CODSettings";
static const midTransSettings = "midTransSettings";
static const orangeMoneySettings = "orangeMoneySettings";
static const xenditSettings = "xenditSettings";
static late SharedPreferences pref;
static Future<void> initPref() async {
pref = await SharedPreferences.getInstance();
}
/// Get boolean safely, fallback if stored value is string
static bool getBoolean(String key) {
final value = pref.get(key);
if (value is bool) return value;
if (value is String) {
// fallback for old string "Dark"/"Light"
return value.toLowerCase() == "dark";
}
return 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);
}
}

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

@@ -0,0 +1,125 @@
import 'package:customer/constant/constant.dart';
import 'package:customer/widget/place_picker/selected_location_model.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get_utils/src/extensions/internacionalization.dart';
import 'package:map_launcher/map_launcher.dart';
import '../themes/show_toast_dialog.dart';
import 'package:geocoding/geocoding.dart';
import 'package:location/location.dart' as loc;
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 loc.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<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 ?? ''}";
return address;
}
return "Unknown location";
} catch (e) {
return "Unknown location";
}
}
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".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));
} else {
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));
} else {
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));
} else {
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));
} else {
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));
} else {
ShowToastDialog.showToast("yandexMaps map is not installed".tr);
}
}
}
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) {
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!);
return parts.join(', ');
}
}