Giter Club home page Giter Club logo

Comments (9)

ryanheise avatar ryanheise commented on June 14, 2024

There is already a line of code written to enable this but it is commented out because it's unclear how this should work in all use cases. Here are the use cases I can think of:

  1. You want the tap to do nothing
  2. You want the tap to take you to the main screen of the app
  3. You want the tap to take you to a deep link within the app

(1) and (2) should be straightforward but I'm not sure how to implement (3) in a way that understands Flutter's routes.

Which use case fits your app? If it's (2), I may just add an option for you as a short term fix and leave (3) an open problem for the future. If it's (3), perhaps you could share with me how you plan to navigate to the appropriate screen once your FlutterActivity is started from this tap.

from audio_service.

alexantenna avatar alexantenna commented on June 14, 2024

My app shows on-screen player on all screens so 2) looks like reasonable option for now - it's way better than nothing :-), but 3) of course is more promising.

from audio_service.

alexantenna avatar alexantenna commented on June 14, 2024

Regarding 3), I think that it's application responsibility to decide which behaviour it should implement on launching the app from notification. The plugin responsibility is only to notify that app was started (opened) from notification and let's application decide what to do with this fact.

Authors of Flutter Local Notification plugin provide such functionality - you may register notification tap callback in app's code (even with passed payload parameter) when do what you want in this callback.

flutterLocalNotificationsPlugin.initialize(initializationSettings,
    onSelectNotification: onSelectNotification);

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

What do you think about the effort of implementing the same behaviour in your plugin, is it large enough or not?

from audio_service.

ryanheise avatar ryanheise commented on June 14, 2024

Thanks for the suggestion and I agree that the actual routing / deep linking should be the responsibility of the application. The Flutter Local Notifications plugin uses an interesting approach, although fortunately I think audio_service can be much simpler since it has narrower use cases.

I added support for clicking on the notification which supports (2) out of the box and should support (3) although I would like to test that. It's pushed to the GitHub repo but not yet published to the package server.

The way it works is: when you click on the notification, it starts your main activity. Since by default, your activity has a launch mode of singleTop, it will actually just resume the existing activity that is already in memory which means that all the state including routes should be preserved. In other words, (3) will also work out of the box PROVIDED that the activity is still in memory. If it is not, then a new instance of the activity will be created. Then, you can use something like if (AudioService.running) in your flutter initialisation code to determine which screen you want to show to reconstruct the correct state.

from audio_service.

alexantenna avatar alexantenna commented on June 14, 2024

Thanks for being so responsive, hope I will try new versions right from git this evening - let you know how it will go.

from audio_service.

ryanheise avatar ryanheise commented on June 14, 2024

FYI I've published release 0.0.4 to the package server which includes this functionality.

from audio_service.

alexantenna avatar alexantenna commented on June 14, 2024

Great, will try, thanks for your support!

from audio_service.

alexantenna avatar alexantenna commented on June 14, 2024

It works, closing...

from audio_service.

github-actions avatar github-actions commented on June 14, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.

from audio_service.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.