Comments (1)
Hi @calvinmuller-wi,
That's a great question, thanks for reaching out.
We recommend creating a top-level variable to hold a reference to your State<>
class context, which can be accessed inside the backgroundNotificationListener
, to pass notifications to your Widget
context as follows:
- Add a top-level variable to your
lib/main.dart
, replacing_PushyDemoState
with your ownState<>
class name:
_PushyDemoState currentState;
- Add this code in the
void initState() {}
method of yourState
class implementation:
@override
void initState() {
super.initState();
// Start the Pushy service
Pushy.listen();
// Pass reference to State context
currentState = this;
}
- Add a new method in your
State<>
class to process notifications in foreground:
void onNewNotification(Map<String, dynamic> data) {
// ....
}
- Access the state in
backgroundNotificationsListener
(will be null if it's running in the background) and invoke your method:
void backgroundNotificationListener(Map<String, dynamic> data) {
// Print notification payload data
print('Received notification: $data');
// If app is in foreground, pass notification to Widget
if (currentState != null) {
currentState.onNewNotification(data);
}
// .......
}
Please let us know if you have any further questions or face any issues.
from pushy-flutter.
Related Issues (20)
- backgroundNotificationListener not called when app built with --split-debug-info is killed. HOT 18
- Can't save to local storage of notification received on ios when app is closed HOT 4
- iOS device - "Pushy: Error retrieving handle for Flutter callbacks" HOT 1
- Installing background listener fails in release mode HOT 9
- iOS app killed - Click on notification not open specific screen HOT 2
- iOS Push permission deined HOT 1
- A blank screen appears when app is killed and user taps on a notification HOT 2
- Android Notification HOT 10
- Web support HOT 1
- Dialog pop in IOS when app is in foreground. HOT 2
- Infinix Mobile Notification Issue HOT 1
- Crashes and Freezes Pushy.Register() on VIVO and OPPO devices . HOT 1
- Status Bar Notification Issue In Android HOT 3
- Feature: Support for Linux HOT 1
- Pushy.register get device token giving error HOT 1
- Token is not generating Pushy in IOS HOT 3
- Android , Pushy ( 7552): Notifications have been disabled by the app HOT 2
- Please, update dependencies HOT 4
- await Pushy.register() HOT 8
- Unable to send notification on deivce id in flutter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pushy-flutter.