FirebaseMessaging.onMessageOpenedApp.listen never trigered #6701
Unanswered
NikhilKottarathil
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
import 'dart:async';
import 'dart:convert';
import 'package:ev_charge/authentication/location_permission.dart';
import 'package:ev_charge/authentication/splash_screen.dart';
import 'package:ev_charge/blocs/application_bloc.dart';
import 'package:ev_charge/functions/api_calls.dart';
import 'package:ev_charge/my_wallet.dart';
import 'package:ev_charge/providers/FavouriteProvider.dart';
import 'package:ev_charge/providers/basic_provider.dart';
import 'package:ev_charge/providers/booking_provider.dart';
import 'package:ev_charge/providers/staion_and_machine_provider.dart';
import 'package:ev_charge/providers/vehicle_provider.dart';
import 'package:ev_charge/tabs/Ordering/ordering_step_3.dart';
import 'package:ev_charge/tabs/profile.dart';
import 'package:ev_charge/vehicle/vehicle_details_request.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:provider/provider.dart';
Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call
initializeApp
before using other Firebase services.await Firebase.initializeApp();
;
}
AndroidNotificationChannel channel = const AndroidNotificationChannel(
'high_importance_channel', // id
'High Importance Notifications', // title
'This channel is used for important notifications.', // description
importance: Importance.high,
);
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
// Set the background messaging handler early on, as a named top-level function
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
runApp(new MyApp());
}
// Future selectNotificationBackGround(String payload) async {
// await Future.delayed(const Duration(milliseconds: 200),
// () => Navigator.pushNamed(MyApp.navigatorKey.currentContext, '/Profile'));
// }
Future selectNotification(String payload) async {
print('selected Notification');
print(payload);
var messageData = json.decode(payload);
var messageType = messageData['type'];
if (messageType == 'wallet') {
await Future.delayed(
const Duration(milliseconds: 200),
() => MyApp.navigatorKey.currentState
.push(MaterialPageRoute(builder: (context) => MyWallet())));
Provider.of(MyApp.navigatorKey.currentContext, listen: false)
.setTabBarInitialIndex(4);
} else if (messageType == 'order') {
await Future.delayed(
const Duration(milliseconds: 200),
() => MyApp.navigatorKey.currentState.push(MaterialPageRoute(
builder: (context) => OrderingStep3(
orderID: messageData['order_id'],
parentPage: 'Main',
))));
} else {
//for machine add section
}
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
static final navigatorKey = new GlobalKey();
@OverRide
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State {
String token;
@OverRide
void initState() {
// TODO: implement initState
super.initState();
}
@OverRide
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white,
statusBarIconBrightness: Brightness.dark));
}
getToken() async {
token = await FirebaseMessaging.instance.getToken();
setState(() {
token = token;
});
print(token);
}
Future setupInteractedMessage() async {
// Get any messages which caused the application to open from
// a terminated state.
RemoteMessage initialMessage =
await FirebaseMessaging.instance.getInitialMessage();
}
}
Beta Was this translation helpful? Give feedback.
All reactions