diff --git a/shorebird_code_push/README.md b/shorebird_code_push/README.md index 6735f1a..0632876 100644 --- a/shorebird_code_push/README.md +++ b/shorebird_code_push/README.md @@ -37,16 +37,51 @@ import 'package:shorebird_code_push/shorebird_code_push.dart'; // Create an instance of the ShorebirdCodePush class final shorebirdCodePush = ShorebirdCodePush(); -// Get the current patch number, or null if no patch is installed. -final currentPatchversion = shorebirdCodePush.currentPatchNumber(); +// Launch your app +void main() { + runApp(const MyApp()); +} -// Check whether a patch is available to install. -final isUpdateAvailable = await shorebirdCodePush.isNewPatchAvailableForDownload(); +// [Other code here] -// Download a new patch. -await shorebirdCodePush.downloadUpdateIfAvailable(); +class _MyHomePageState extends State { + @override + void initState() { + super.initState(); + + // Get the current patch number and print it to the console. It will be + // null if no patches are installed. + shorebirdCodePush + .currentPatchNumber() + .then((value) => print('current patch number is $value')); + } + + Future _checkForUpdates() async { + // Check whether a patch is available to install. + final isUpdateAvailable = await shorebirdCodePush.isNewPatchAvailableForDownload(); + + if (isUpdateAvailable) { + // Download the new patch if it's available. + await shorebirdCodePush.downloadUpdateIfAvailable(); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + // [Other code here] + ElevatedButton( + child: Text('Check for update'), + onPressed: _checkForUpdates, + ) + // [Other code here] + ); + } +} ``` +See the example for a complete working app. + ## Join us on Discord! We have an active [Discord server](https://discord.gg/shorebird) where you can