-
-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathmain_custom_alert.dart
More file actions
97 lines (85 loc) · 2.6 KB
/
main_custom_alert.dart
File metadata and controls
97 lines (85 loc) · 2.6 KB
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
// Copyright (c) 2023 Larry Aasen. All rights reserved.
import 'package:flutter/material.dart';
import 'package:upgrader/upgrader.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Only call clearSavedSettings() during testing to reset internal values.
await Upgrader.clearSavedSettings(); // REMOVE this for release builds
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
final upgrader = MyUpgrader(debugLogging: true);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Upgrader Example',
home: MyUpgradeAlert(
upgrader: upgrader,
child: Scaffold(
appBar: AppBar(title: const Text('Upgrader Custom Alert Example')),
body: const Center(child: Text('Checking...')),
)),
);
}
}
class MyUpgrader extends Upgrader {
MyUpgrader({super.debugLogging});
@override
bool isUpdateAvailable() {
final storeVersion = currentAppStoreVersion;
final installedVersion = currentInstalledVersion;
print('storeVersion=$storeVersion');
print('installedVersion=$installedVersion');
return super.isUpdateAvailable();
}
}
class MyUpgradeAlert extends UpgradeAlert {
MyUpgradeAlert({super.key, super.upgrader, super.child});
/// Override the [createState] method to provide a custom class
/// with overridden methods.
@override
UpgradeAlertState createState() => MyUpgradeAlertState();
}
class MyUpgradeAlertState extends UpgradeAlertState {
@override
void showTheDialog({
Key? key,
required BuildContext context,
required String? title,
required String message,
required String? releaseNotes,
required bool barrierDismissible,
required UpgraderMessages messages,
}) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
key: key,
title: const Text('Update?'),
content: const SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('Would you like to update?'),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('No'),
onPressed: () {
onUserIgnored(context, true);
},
),
TextButton(
child: const Text('Yes'),
onPressed: () {
onUserUpdated(context, !widget.upgrader.blocked());
},
),
],
);
});
}
}