Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
Niris1 opened this issue Aug 27, 2024 · 3 comments
Closed
1 task done

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

Niris1 opened this issue Aug 27, 2024 · 3 comments

Comments

@Niris1
Copy link

Niris1 commented Aug 27, 2024

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

  • I agree to follow this project's Code of Conduct
@jennantilla
Copy link
Contributor

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

@Niris1
Copy link
Author

Niris1 commented Sep 4, 2024 via email

@jennantilla
Copy link
Contributor

Hello @Niris1 did you ever get this figured out?

We do have a notification click listener that you can use to know that the app was opened by a notification.

Let us know if you have any additional questions or concerns!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants