-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
95 lines (82 loc) · 2.67 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
// ignore_for_file: avoid_print
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_prince_of_versions/flutter_prince_of_versions.dart';
import 'my_callback.dart';
void main() {
runApp(const MaterialApp(home: Scaffold(body: MyApp())));
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static const androidUrl = 'https://pastebin.com/raw/FBMxHpN7';
static const iOSUrl = 'https://pastebin.com/raw/0MfYmWGu';
Future<void> _checkForUpdates() async {
String url = Platform.isAndroid ? androidUrl : iOSUrl;
try {
final updateData = await FlutterPrinceOfVersions.checkForUpdates(
url: url,
requirementChecks: {
'region': (value) {
return value == 'hr';
},
'bluetooth': (value) {
return value == '5.0';
}
},
);
print('Update status: ${updateData.status}');
print('Installed version: ${updateData.updateInfo.installedVersion}');
print('Last version: ${updateData.updateInfo.lastVersionAvailable}');
print('Metadata: ${updateData.metadata}');
} catch (error) {
print(error);
}
}
Future<void> _checkForUpdatesFromAppStore() async {
final updateData =
await FlutterPrinceOfVersions.checkForUpdatesFromAppStore();
print('Update status: ${updateData.status}');
print('Current version: ${updateData.version}');
}
Future<void> _checkForUpdatesFromGooglePlay() async {
final callback = MyCallback(context);
await FlutterPrinceOfVersions.checkForUpdatesFromGooglePlay(
"Google Play url", callback);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Column(
children: <Widget>[
const SizedBox(height: 100),
const Center(
child: Text(
'Prince of Versions example',
style: TextStyle(fontSize: 24),
),
),
const SizedBox(height: 40),
CupertinoButton.filled(
onPressed: _checkForUpdates,
child: const Text('Check for updates'),
),
const SizedBox(height: 20),
CupertinoButton.filled(
onPressed: _checkForUpdatesFromAppStore,
child: const Text('Check App Store updates'),
),
const SizedBox(height: 20),
CupertinoButton.filled(
onPressed: _checkForUpdatesFromGooglePlay,
child: const Text('Check Google Play updates'),
),
],
),
);
}
}