I’m developing a flutter app using fcm and all notifications are working well.
And i want to display a red notification badge on home screen when a message received.
However, when Android in background and enter foreground again, UI doesn’t chage.
It isn’t updated.
Android:
- foreground – works well
- background – doesn’t work
- terminated – works well
iOS:
- foreground – works well
- background – works well
- terminated – works well
showNotification
// Change the value, when message is received,
Future<void> showNotification(RemoteMessage message) async {
final readNotiController = Get.put(ReadNotiController());
readNotiController.isRead.value = false;
readNotiController.storeisReadInfo(false);
...
}
controller
// Checks if user readnotification
class ReadNotiController extends GetxController {
RxBool isRead = true.obs;
Future<void> storeisReadInfo(value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool('isRead', value);
}
}
UI update
// Update ui according to controller
Obx(() => Positioned(
left: screenSize.width / 2 - 75,
child: readNotiController.isRead.value
? Container() // read
: Container( // unread
decoration: BoxDecoration(
color: const Color(0xffff3939),
shape: BoxShape.circle,
border: Border.all(
color: const Color(0xfff2f2f2),
width: 4,
),
)
)
)
I thought this problem caused by difference in background between Android and iOS.
Why doesn’t UI update when changing from background to foreground in Android?
If you have any good opinions please help me !!!