wip notif

This commit is contained in:
Thomas Fransolet 2023-08-01 16:49:34 +02:00
parent 8924bc30e8
commit 11cca4d044
5 changed files with 45 additions and 14 deletions

View File

@ -6,6 +6,12 @@ if (localPropertiesFile.exists()) {
}
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
@ -93,11 +99,20 @@ android {
*/
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
debuggable false
@ -118,6 +133,7 @@ dependencies {
// When using the BoM, don't specify versions in Firebase dependencies
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-messaging-directboot'
// Add the dependencies for any other desired Firebase products
// https://firebase.google.com/docs/android/setup#available-libraries

View File

@ -1,5 +1,5 @@
#Mon Jul 31 16:50:59 CEST 2023
VERSION_BUILD=43
#Tue Aug 01 16:05:42 CEST 2023
VERSION_BUILD=59
VERSION_MAJOR=1
VERSION_MINOR=0
VERSION_PATCH=0

View File

@ -10,10 +10,6 @@ import 'package:myhomie_app/Models/homieContext.dart';
import '../constants.dart';
class PushNotificationService {
//final FirebaseMessaging _fcm;
PushNotificationService(); //this._fcm
goToPage(Map<String, dynamic> message) {
var notification = PushNotificationMessage(
title: message['notification']['title'],
@ -36,12 +32,22 @@ class PushNotificationService {
);
}
Future initialise(HomieAppContext? homieAppContext, {required BuildContext context}) async {
Future initialise(HomieAppContext? homieAppContext, BuildContext context, [bool inMain = false]) async {
if (Platform.isIOS) {
//_fcm.requestPermission(); // IosNotificationSettings
FirebaseMessaging.instance.requestPermission();
}
NotificationSettings settings = await FirebaseMessaging.instance.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
//_fcm.subscribeToTopic("main");
FirebaseMessaging.instance.subscribeToTopic("main");
@ -95,13 +101,17 @@ class PushNotificationService {
);
}*/
NotificationManager.handleNotificationMsg(notification, context);
// show notification UI here
if(!inMain) {
// show notification UI here
NotificationManager.handleNotificationMsg(notification, context);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print('A new onMessageOpenedApp event was published!');
// TODO navigate somewhere in the app depending the coming message
/*Navigator.pushNamed(
context,
'/message',
@ -149,6 +159,7 @@ class DataNotification {
});
}
@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print("Handling a background message");
}

View File

@ -5,6 +5,7 @@ import 'package:myhomie_app/Components/Custom_Navigation_Bar/custom_app_bar.dart
import 'package:myhomie_app/Components/Custom_Navigation_Bar/custom_bottom_navigation_bar.dart';
import 'package:myhomie_app/Components/Custom_Navigation_Bar/custom_nav_item.dart';
import 'package:myhomie_app/Helpers/MQTTHelper.dart';
import 'package:myhomie_app/Helpers/PushNotificationService.dart';
import 'package:myhomie_app/Screens/Debug/DebugPage.dart';
import 'package:myhomie_app/Screens/Main/Automations/automations.dart';
import 'package:myhomie_app/Screens/Main/Devices/devices.dart';
@ -50,6 +51,8 @@ class _MainPageState extends State<MainPage> {
print("MQTT NOT INSTANTIATED");
MQTTHelper.instance.connect(appContext);
}
final pushNotificationService = PushNotificationService();
pushNotificationService.initialise(homieAppContext, context);
return ChangeNotifierProvider<Index>(
create: (_) => Index(0, appContext.getContext()),

View File

@ -58,13 +58,14 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
final pushNotificationService = PushNotificationService();
pushNotificationService.initialise(widget.homieAppContext, context: context);
/*final pushNotificationService = PushNotificationService();
pushNotificationService.initialise(widget.homieAppContext, context, true);*/
return ChangeNotifierProvider<AppContext>(
create: (_) => AppContext(widget.homieAppContext),
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'MyHomie App Demo',
title: 'MyHomie App',
initialRoute: widget.initialRoute,
/*supportedLocales: [
const Locale('en', 'US'),
@ -74,7 +75,7 @@ class _MyAppState extends State<MyApp> {
primarySwatch: Colors.blue,
scaffoldBackgroundColor: kBackgroundColor,
//fontFamily: "Vollkorn",
textTheme: TextTheme(bodyText1: TextStyle(color: kBodyTextColor)),
textTheme: TextTheme(bodyLarge: TextStyle(color: kBodyTextColor)),
visualDensity: VisualDensity.adaptivePlatformDensity,
),
routes: {