/
main.dart
108 lines (96 loc) · 3.12 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// ignore_for_file: invalid_use_of_visible_for_testing_member, avoid_print
import 'package:flutter/material.dart';
import 'package:update_helper/update_helper.dart';
void main() {
runApp(const MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final updateHelper = UpdateHelper.instance;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
// Adding testing package name, don't need this in real app
updateHelper.packageName = 'com.vursin.othello';
print('Show normal update dialog. Just press Later');
await UpdateHelper.instance.initial(
context: context,
updateConfig: UpdateConfig(
defaultConfig: UpdatePlatformConfig(latestVersion: '0.0.6'),
),
changelogs: ['Improve performances', 'Update UI'],
isDebug: true,
);
print('Don\'t show dialog because [onlyShowDialogWhenForce] is `true`'
'but [forceUpdate] is `false`');
if (mounted) {
await UpdateHelper.instance.initial(
context: context,
updateConfig: UpdateConfig(
defaultConfig: UpdatePlatformConfig(latestVersion: '0.0.6'),
),
onlyShowDialogWhenBanned: true,
changelogs: ['Improve performances', 'Update UI'],
isDebug: true,
);
}
print('Show a custom dialog');
if (mounted) {
await UpdateHelper.instance.initial(
context: context,
updateConfig: UpdateConfig(
defaultConfig: UpdatePlatformConfig(latestVersion: '0.0.6'),
),
isDebug: true,
dialogBuilder: (context, config) {
return AlertDialog.adaptive(
title: const Text('Update'),
content: const Text(
'This is a custom dialog.\n\nWould you like to update?'),
actions: [
TextButton(
onPressed: config.onOkPressed, child: const Text('OK')),
TextButton(
onPressed: config.onLaterPressed,
child: Text(
'Later',
style: TextStyle(color: Theme.of(context).disabledColor),
),
),
],
);
},
);
}
print('Show dialog because [onlyShowDialogWhenForce] is `true`'
'and [forceUpdate] is `true`');
if (mounted) {
await UpdateHelper.instance.initial(
context: context,
updateConfig: UpdateConfig(
defaultConfig: UpdatePlatformConfig(latestVersion: '0.0.6'),
),
onlyShowDialogWhenBanned: true,
forceUpdate: true,
isDebug: true,
);
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const Center(
child: Text(''),
),
);
}
}