A Flutter package for checking if there is a new PWA version, and it is ready to be update.
Wrap PwaUpdateListener
around a widget in the main page. onReady
will be called when the child widget is shown (eg. when a page is pop and the main page is shown) or when the app return from background.
Scaffold(
body: PwaUpdateListener(
onReady: () {
/// Show a snackbar to get users to reload into a newer version
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Expanded(child: Text('A new update is ready')),
TextButton(
onPressed: () {
reloadPwa();
},
child: Text('UPDATE'),
),
],
),
duration: Duration(days: 365),
behavior: SnackBarBehavior.floating,
),
);
},
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
),
);