OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
615 stars 213 forks source link

[question]: Listen to notifications opening a page #942

Open Niris1 opened 2 weeks ago

Niris1 commented 2 weeks ago

How can we help?

import 'package:flutter/material.dart'; import 'dart:async'; // import 'main.dart'; import '../configurations.dart';

class SplashScreen extends StatefulWidget { const SplashScreen({super.key});

@override // ignore: library_private_types_in_public_api _SplashScreenState createState() => _SplashScreenState(); }

class _SplashScreenState extends State { List assetImages = [ const AssetImage( "assets/images/depositphotos_371485238-stock-photo-abstract-black-texture-concrete-wall.jpg"), const AssetImage("assets/images/RHzvO.png"), const AssetImage("assets/images/Synectics-logo-big-300x77.png") ];

int curImage = 0; var howToFit = BoxFit.cover; late Timer _timer;

@override void initState() { super.initState(); _startImageSlideshow(); }

void _startImageSlideshow() { _timer = Timer.periodic(const Duration(seconds: 3), (timer) { setState(() { curImage++; if (curImage == 2) { howToFit = BoxFit.fitWidth; } if (curImage >= assetImages.length - 1) { _goHome(); _timer.cancel(); } }); }); }

Future _goHome() async { await Future.delayed(const Duration(seconds: 3)); Navigator.pushReplacement( // ignore: use_build_context_synchronously context, MaterialPageRoute( builder: (context) => const ConfigurationScreen()), ); }

@override void dispose() { _timer.cancel(); super.dispose(); }

@override Widget build(BuildContext context) { return Scaffold( body: SizedBox.expand( child: AnimatedSwitcher( duration: const Duration(seconds: 1), transitionBuilder: (Widget child, Animation animation) { return FadeTransition( opacity: animation, child: child, ); }, child: SizedBox( key: ValueKey(curImage), width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, child: Image( image: assetImages[curImage], fit: howToFit, ), ), ), ), ); } }

I have this intro screen where i alternate between 3 images and then navigate to the configuration screen..I added onesignal today and while testing the API I send me a notification that navigates to a different page in my app.. The issue is when the app isnt running in the background it navigates to the correct route i send it with the notification but after a few seconds _goHome from this page kicks in and redirects to the configuration screen.

Code of Conduct

jennantilla commented 1 week ago

Hello @Niris1 thanks for reaching out! Could you please provide the debug logs reproducing this behavior? Thanks!

Niris1 commented 1 week ago

Hello and thanks for the swift reply!

The problem is probably with my code,but it would be nice to have a way to know that the app was opened by a notification so I can stop a certain function from running in the background.

On Tue, Sep 3, 2024 at 10:49 PM Jenna Antilla @.***> wrote:

Hello @Niris1 https://github.com/Niris1 thanks for reaching out! Could you please provide the debug logs https://documentation.onesignal.com/docs/capturing-a-debug-log reproducing this behavior? Thanks!

— Reply to this email directly, view it on GitHub https://github.com/OneSignal/OneSignal-Flutter-SDK/issues/942#issuecomment-2327308293, or unsubscribe https://github.com/notifications/unsubscribe-auth/BJ5LQE7H6NZ4NC23QL4RN6DZUYHDNAVCNFSM6AAAAABNGE3RCWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRXGMYDQMRZGM . You are receiving this because you were mentioned.Message ID: @.***>