Change flutter version + add manual-update
This commit is contained in:
parent
13cb97b4b8
commit
2519513638
11 changed files with 151 additions and 21 deletions
|
|
@ -1,9 +1,82 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shorebird_code_push/shorebird_code_push.dart';
|
||||
import 'package:restart_app/restart_app.dart';
|
||||
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class ShorebirdPatch extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ShorebirdPatchState();
|
||||
}
|
||||
|
||||
enum PatchState {
|
||||
loading,
|
||||
noUpdate,
|
||||
updateReady;
|
||||
}
|
||||
|
||||
class _ShorebirdPatchState extends State<ShorebirdPatch> {
|
||||
final shorebird = ShorebirdCodePush();
|
||||
late Timer timer;
|
||||
PatchState patchState = PatchState.noUpdate;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
timer = Timer.periodic(const Duration(minutes: 5), (timer) async {
|
||||
if (!shorebird.isShorebirdAvailable()) {
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
if (!await shorebird.isNewPatchAvailableForDownload()) {
|
||||
setState(() {
|
||||
patchState = PatchState.noUpdate;
|
||||
});
|
||||
return;
|
||||
}
|
||||
final download = shorebird.downloadUpdateIfAvailable();
|
||||
setState(() {
|
||||
patchState = PatchState.loading;
|
||||
});
|
||||
await download;
|
||||
if (await shorebird.isNewPatchReadyToInstall()) {
|
||||
setState(() {
|
||||
patchState = PatchState.updateReady;
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
timer.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
switch (patchState) {
|
||||
case PatchState.loading:
|
||||
return const SizedBox.square(dimension: 48, child: Center(child: CircularProgressIndicator()));
|
||||
case PatchState.noUpdate:
|
||||
return const SizedBox.shrink();
|
||||
case PatchState.updateReady:
|
||||
return InkWell(
|
||||
child: const SizedBox.square(dimension: 48, child: Icon(Icons.update, size: 24)),
|
||||
onTap: () {
|
||||
Restart.restartApp();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
|
|
@ -22,6 +95,7 @@ class MyApp extends StatelessWidget {
|
|||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
|
|
@ -43,6 +117,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
actions: [ShorebirdPatch()],
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue