Skip to content

Commit

Permalink
docs(shorebird_code_push): improve example in readme (shorebirdtech#102)
Browse files Browse the repository at this point in the history
* docs(shorebird_code_push): improve example in readme

* wording
  • Loading branch information
bryanoltman authored Oct 20, 2023
1 parent ef20c33 commit 5182397
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions shorebird_code_push/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// Check whether a patch is available to install.
final isUpdateAvailable = await shorebirdCodePush.isNewPatchAvailableForDownload();
// Download a new patch.
await shorebirdCodePush.downloadUpdateIfAvailable();
// Launch your app
void main() {
runApp(const MyApp());
}
// [Other code here]
class _MyHomePageState extends State<MyHomePage> {
@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<void> _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
Expand Down

0 comments on commit 5182397

Please sign in to comment.