Check Mobile App
Read now

Broadcast Receiver In Flutter

Save

Before starting the blog topic Broadcast Receiver In Flutter, let’s discuss what is the Broadcast Receiver? Basically, the Broadcast receiver is the application component that helps us register some receiver against some events. The receivers that we registered in the application, will receive the broadcast when the events occur or are triggered.

In the Flutter, we can use the “fbroadcast” for registering the receivers for the events on which we want to perform some widgets state changes at any time or location.
For example, we have PAGE A, PAGE B, and PAGE C in the Flutter App. On PAGE C, we will perform some action like, change the image of the user or the name of the use. Which we want to quickly reflect on PAGE A. So this can be achieved by the “fbroadcast” in the flutter app. For implementing the Broadcast Receiver In Flutter, we will follow the mentioned steps:

1.  Adding the fbroadcast dependency in the “pubspec. yaml”

I have used the following version dependency, you can use any version as per your requirement from the Flutter Dev console.

2.  Register the receiver

These are the most important steps to receive the events that will be triggered any time from any location of the application. For which you want to receive any update and change the state of the widget or perform some action.

 

NOTE:
1. Key_Message = This key will be the name of the events for which you are registering the receiver.
2. value = FBroadcast allows developers to include data when sending messages. You can choose to persist specific types of messages so that they can easily implement broadcast-style global state management.

3. Sending the Broadcast

After registering the event in a particular class, now we will trigger the event with some data, so it can be captured or received by the registered receiver.

 

NOTE:
1. Key_Message = This key will be the name of the events for which you are registering the receiver. The name should be the same in both places so it can be captured by the respected receiver.

2. value = In this demo, I have sent the value from the input field and set the same value to the text field of the previous page. You can also use any data type or custom data type as per the requirements.

4. Close the Receiver

This is the last step but not least. After the application destroys, we can unregister all the receivers from the class in the onDispose() method.

5.  Sticky Broadcast

FBroadcast allows developers to send Sticky Broadcasts. The sticky broadcast will temporarily stay in the system until a receiver of this type is registered, and the broadcast will be sent out immediately (when the broadcast send )

 

Conclusion

In this blog, we have read about the Broadcast Receiver In Flutter.

I hope it will help you out in understanding and getting a brief idea about it.

Thank you for reading!!

For more information, please go through the Flutter Dev console

 

 

 

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

Deniel Kerr

Owner and Founder. Opencart

Talk to Sales
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home