- Replace all Firebase* repositories with Api* repositories using HTTP + SharedPreferences JWT - Remove Firebase.initializeApp() and firebase_messaging background handler from main.dart - Update DI (app_di.dart) to inject Api* repositories instead of Firebase* ones - Replace all Timestamp/cloud_firestore usage with ISO 8601 String dates - Stub PhoneVerificationService (Firebase phone OTP → backend OTP when implemented) - Add ApiService singleton with JWT management in lib/services/ - Legacy firebase_*_repository.dart files preserved for Fase 4 cleanup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
98 lines
2.7 KiB
Dart
98 lines
2.7 KiB
Dart
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'dart:convert';
|
|
import 'package:prosappco/constansts.dart' show API_BASE_URL;
|
|
|
|
class LocalNotifications {
|
|
static Future<void> requestPermissionLocalNotifications() async {
|
|
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
|
|
|
await flutterLocalNotificationsPlugin
|
|
.resolvePlatformSpecificImplementation<
|
|
AndroidFlutterLocalNotificationsPlugin>()
|
|
?.requestNotificationsPermission();
|
|
}
|
|
|
|
static Future<void> initializeLocalNotifications() async {
|
|
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
|
|
|
const initializationSettingsAndroid =
|
|
AndroidInitializationSettings('app_icon');
|
|
|
|
const DarwinInitializationSettings initializationSettingsIOS =
|
|
DarwinInitializationSettings(
|
|
requestAlertPermission: true,
|
|
requestBadgePermission: true,
|
|
requestSoundPermission: true,
|
|
);
|
|
|
|
const initializationSettings = InitializationSettings(
|
|
android: initializationSettingsAndroid,
|
|
iOS: initializationSettingsIOS,
|
|
);
|
|
|
|
await flutterLocalNotificationsPlugin.initialize(
|
|
initializationSettings,
|
|
);
|
|
}
|
|
|
|
static void showLocalNotification({
|
|
required int id,
|
|
String? title,
|
|
String? body,
|
|
String? data,
|
|
}) {
|
|
const androidDetails = AndroidNotificationDetails(
|
|
'channel_id',
|
|
'channel_name',
|
|
importance: Importance.max,
|
|
priority: Priority.high,
|
|
playSound: true,
|
|
sound: RawResourceAndroidNotificationSound('notification'),
|
|
);
|
|
|
|
|
|
// IOSNotificationDetails --> DarwinNotificationDetails
|
|
const DarwinNotificationDetails iOSNotificationDetails =
|
|
DarwinNotificationDetails(
|
|
presentAlert: true,
|
|
presentBadge: true,
|
|
presentSound: true,
|
|
);
|
|
const NotificationDetails notificationDetails = NotificationDetails(
|
|
android: androidDetails, iOS: iOSNotificationDetails);
|
|
|
|
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
|
|
|
flutterLocalNotificationsPlugin.show(
|
|
id,
|
|
title,
|
|
body,
|
|
notificationDetails,
|
|
payload: data,
|
|
);
|
|
}
|
|
|
|
static Future<void> sendPushNotification(
|
|
String token, String title, String body) async {
|
|
try {
|
|
http.Response response = await http.post(
|
|
Uri.parse('$API_BASE_URL/notifications/send'),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
},
|
|
body: jsonEncode(
|
|
<String, dynamic>{
|
|
'title': title,
|
|
'body': body,
|
|
'to': token,
|
|
},
|
|
),
|
|
);
|
|
response;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|