2026-04-15

This commit is contained in:
mageshwaran committed 2026-04-15 12:32:30 +05:30
1 parent d01e5ba860
commit 96de59e9be
46 files changed
+1299 -1191

No files matched your search

+89 -5
View File
@@ -2,6 +2,7 @@ import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';
import 'package:taxglide/consts/download_helper.dart';
import 'package:taxglide/consts/local_store.dart';
import 'package:taxglide/view/Mahi_chat/live_chat_screen.dart';
import 'package:taxglide/view/Main_controller/main_controller.dart';
@@ -26,6 +27,16 @@ const AndroidNotificationChannel _channel = AndroidNotificationChannel(
enableVibration: true,
);
/// Android notification channel for download updates.
const AndroidNotificationChannel _downloadChannel = AndroidNotificationChannel(
'taxglide_downloads',
'TaxGlide Downloads',
description: 'Notifications for file downloads',
importance: Importance.high,
playSound: true,
enableVibration: true,
);
/// Call once in main() after Firebase.initializeApp().
Future<void> initLocalNotifications() async {
const initSettings = InitializationSettings(
@@ -37,19 +48,34 @@ Future<void> initLocalNotifications() async {
initSettings,
onDidReceiveNotificationResponse: (NotificationResponse response) {
// Notification tapped while app is open – handled inside NotificationService.
debugPrint('🔔 Local notification tapped: payload=${response.payload}');
debugPrint('🔔 Local notification action: ${response.actionId} payload=${response.payload}');
if (response.actionId == 'location') {
final payload = response.payload;
if (payload != null && payload.startsWith('download:')) {
final filePath = payload.replaceFirst('download:', '');
final String dirPath = filePath.substring(0, filePath.lastIndexOf('/'));
debugPrint('📂 Opening folder from notification: $dirPath');
// Open the system file manager at this location
DownloadHelper.openFolder(dirPath);
return;
}
}
Get.find<NotificationService>().handleNavigationFromPayload(
response.payload,
);
},
);
// Create the Android channel (no-op on iOS).
await flutterLocalNotificationsPlugin
// Create the channels
final androidPlugin = flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin
>()
?.createNotificationChannel(_channel);
>();
await androidPlugin?.createNotificationChannel(_channel);
await androidPlugin?.createNotificationChannel(_downloadChannel);
debugPrint('✅ LocalNotifications initialized');
}
@@ -123,6 +149,55 @@ class NotificationService extends GetxController {
);
}
/// Shows a notification when a file is successfully downloaded.
/// [filename] is the base name of the file.
/// [filePath] is the absolute path to the local file.
void showDownloadNotification(String filename, String filePath) {
debugPrint('📩 NotificationService: showing download success: $filename');
flutterLocalNotificationsPlugin.show(
filename.hashCode.abs() % 100000,
'Download Complete',
'File saved: $filename',
NotificationDetails(
android: AndroidNotificationDetails(
_downloadChannel.id,
_downloadChannel.name,
channelDescription: _downloadChannel.description,
importance: Importance.high,
priority: Priority.high,
icon: '@mipmap/launcher_icon',
playSound: true,
styleInformation: BigTextStyleInformation(
'The file **$filename** has been saved to your downloads folder:\n\n$filePath',
contentTitle: 'Download Complete',
summaryText: 'TaxGlide Download',
htmlFormatContent: true,
htmlFormatTitle: true,
),
actions: <AndroidNotificationAction>[
const AndroidNotificationAction(
'view',
'View File',
showsUserInterface: true,
),
const AndroidNotificationAction(
'location',
'Show in Folder',
showsUserInterface: true,
),
],
),
iOS: const DarwinNotificationDetails(
presentAlert: true,
presentBadge: true,
presentSound: true,
),
),
payload: 'download:$filePath',
);
}
// ── Navigation helpers ──────────────────────────────────────────────────────
/// Called when a local notification is tapped (payload = "type:id").
@@ -131,6 +206,15 @@ class NotificationService extends GetxController {
_safeNavigate(() => Get.offAll(() => MainController()));
return;
}
// ⭐ Handle file download notifications
if (payload.startsWith('download:')) {
final filePath = payload.replaceFirst('download:', '');
debugPrint('📂 Opening downloaded file from notification: $filePath');
DownloadHelper.openDownloadedFile(filePath);
return;
}
final parts = payload.split(':');
final type = parts.isNotEmpty ? parts[0] : null;
final idStr = parts.length > 1 ? parts[1] : null;