MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.45k stars 1.39k forks source link

Notification takes me to the home page not to the desired one! #301

Closed ahmednet0001 closed 5 years ago

ahmednet0001 commented 5 years ago

When i tap on the notification after killing the app, it takes me to the home page not to the desired one! `Future onSelectNotification(String payload) async{ int id=int.parse(payload);

await Navigator.push(MyApp.navigatorKey.currentContext, MaterialPageRoute(builder: (_) => SingleTodo(id))); // MyApp.navigatorKey.currentState.pushNamed('/single-todo',arguments: id);

}`

MaikuB commented 5 years ago

what version of the plugin are you using and what device and OS version is this on? there was a problem on iOS that had been fixed recently. if you're on the latest version and still observing problems then you may need to check your code and provide a sample app to reproduce the problem. there's an example app in this repo that I use to test scenarios like this and it's been working for me

ahmednet0001 commented 5 years ago

Android marshmallow 23 and 0.8.2 of plugin I will try again with different emulator and simple app

MaikuB commented 5 years ago

also check to see if the app calls the plugin's initialize method when it starts up as that is also part of wiring up the callback and seeing if it should be invoked when the app has been launched by tapping on a notification

ahmednet0001 commented 5 years ago

Ok I will do and contact again . Think you

ahmednet0001 commented 5 years ago

It work well , I tried it in a simple two-page application which works well. But when I make middle page and create notification on it to open desired page ,When i tap on the notification after killing the app, it takes me to the home page not to the desired one! and that approach like my case where I schedule notification not in main page ,

Note : when I run app again and tap any button it take me to desired

MaikuB commented 5 years ago

Where abouts do you initialize the plugin to handle the callback? The second page? If so, please refer back to my previous reply

also check to see if the app calls the plugin's initialize method when it starts up as that is also part of wiring up the callback and seeing if it should be invoked when the app has been launched by tapping on a notification

ahmednet0001 commented 5 years ago

`import 'package:flutter/material.dart'; import 'package:test_noftify/middel_page.dart';

void main() { runApp(MyApp()); }

class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(title: 'Flutter Demo Home Page'), ); } }

class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@override _MyHomePageState createState() => _MyHomePageState(); }

class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'You have pushed the button this many times:', ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.push( context, MaterialPageRoute(builder: (context) => MiddelPage()), ); }, tooltip: 'Increment', child: Icon(Icons.add), ), ); } }

`

middle page `import 'package:flutter/material.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:test_noftify/secod_page.dart';

class MiddelPage extends StatefulWidget {

@override _MiddelPageState createState() => _MiddelPageState(); }

class _MiddelPageState extends State { FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

@override void initState() {

super.initState();
_init();

}

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("MiddelPage"), ), body: Container(), floatingActionButton: FloatingActionButton( child: Icon(Icons.alarm_add), onPressed: () { _schedual(); }, ), ); }

_init() { flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); // initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project var initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/ic_launcher'); var initializationSettingsIOS = IOSInitializationSettings( onDidReceiveLocalNotification: _onDidReceiveLocalNotification); var initializationSettings = InitializationSettings( initializationSettingsAndroid, initializationSettingsIOS); flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: _onSelectNotification); }

_schedual() async {

var scheduledNotificationDateTime =
    new DateTime.now().add( Duration(seconds: 10));
var androidPlatformChannelSpecifics =  AndroidNotificationDetails(
    'your other channel id',
    'your other channel name',
    'your other channel description');
var iOSPlatformChannelSpecifics =  IOSNotificationDetails();
NotificationDetails platformChannelSpecifics =  NotificationDetails(
    androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.schedule(
    0,
    'scheduled title',
    'scheduled body',
    scheduledNotificationDateTime,
    platformChannelSpecifics,
    payload: 'test');

} Future _onSelectNotification(String payload) async { if (payload != null) { debugPrint('notification payload: ' + payload); } await Navigator.push( context, new MaterialPageRoute( builder: (context) => SecondScreen( payload: payload, )), ); }

Future _onDidReceiveLocalNotification( int id, String title, String body, String payload) async {}

}

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="test_noftify" android:icon="@mipmap/ic_launcher">

    <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
        <!-- This keeps the window background of the activity showing
             until Flutter renders its first frame. It can be removed if
             there is no splash screen (such as the default splash screen
             defined in @style/LaunchTheme). -->
        <meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"></action>
        </intent-filter>
    </receiver>
    <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />

</application>

`

ahmednet0001 commented 5 years ago

If I tap notification while middle page open or I close app while middle page is opened it work successfully ,

MaikuB commented 5 years ago

From the code you've sent you haven't moved the initialisation to be done when the app starts up. So this isn't actually not a plugin issue but more of a state management one so is something you'll need to work as everyone as has their own approach. I've made one high-level suggestion here. If you need more help though then please use other community resources listed here

ahmednet0001 commented 5 years ago

Think you

ahmednet0001 commented 5 years ago

Think you --- Yes it is state management problems , I do it

dhinadts commented 4 years ago

When the flutter app is not runnig on the device and if the notification comes
the notification launches the app but it doesnt go to the particular page.

ahmednet0001 commented 4 years ago

Hi Dhinakaran Kalaimani I am happy to help you , But currently I work with kotlin But I am remember I have solve problem so kindly explain what is your problem exact

On Sat, Nov 30, 2019 at 1:15 PM Dhinakaran Kalaimani < notifications@github.com> wrote:

When the flutter app is not runnig on the device and if the notification comes the notification launches the app but it doesnt go to the particular page.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/MaikuB/flutter_local_notifications/issues/301?email_source=notifications&email_token=ACYUMHKBHXUMDE2FR22LMMLQWJDLLA5CNFSM4IPZSXIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFQCQ4Y#issuecomment-559949939, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYUMHOSCLKHP3MNPFLI3ODQWJDLLANCNFSM4IPZSXIA .

dhinadts commented 4 years ago

Thanks for your reply. I set local notification in flutter. It directly goes to the screen according with payload. There is no problem when the app is running. Once I quit the app and daily notification comes It wont go to that particular page for the payload instead it opens the app. I want to open the app and go to that page for my payload. Kindly reply with solution.

Thank you.

On Mon, 2 Dec 2019 at 00:49, Ahmed AbdEl-rheem Osman < notifications@github.com> wrote:

Hi Dhinakaran Kalaimani I am happy to help you , But currently I work with kotlin But I am remember I have solve problem so kindly explain what is your problem exact

On Sat, Nov 30, 2019 at 1:15 PM Dhinakaran Kalaimani < notifications@github.com> wrote:

When the flutter app is not runnig on the device and if the notification comes the notification launches the app but it doesnt go to the particular page.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub < https://github.com/MaikuB/flutter_local_notifications/issues/301?email_source=notifications&email_token=ACYUMHKBHXUMDE2FR22LMMLQWJDLLA5CNFSM4IPZSXIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFQCQ4Y#issuecomment-559949939 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ACYUMHOSCLKHP3MNPFLI3ODQWJDLLANCNFSM4IPZSXIA

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MaikuB/flutter_local_notifications/issues/301?email_source=notifications&email_token=AMOHFOFONTUMIQWUXLOCMFDQWQE53A5CNFSM4IPZSXIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFRSZXI#issuecomment-560147677, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMOHFOEOIRK22LZJZ7HUYW3QWQE53ANCNFSM4IPZSXIA .

-- Thanks, Regards, Dhinakaran K 9677096359

abdulllrashid commented 4 years ago

@dhinadts @ahmednet0001 any updates?