-
Notifications
You must be signed in to change notification settings - Fork 60
/
main.dart
155 lines (140 loc) · 4.64 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_version/get_version.dart';
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart';
// The existing imports
// !! Keep your existing impots here !!
/// main is entry point of Flutter application
void main() {
// Desktop platforms aren't a valid platform.
if (!kIsWeb) _setTargetPlatformForDesktop();
return runApp(MyApp());
}
/// If the current platform is desktop, override the default platform to
/// a supported platform (iOS for macOS, Android for Linux and Windows).
/// Otherwise, do nothing.
void _setTargetPlatformForDesktop() {
TargetPlatform targetPlatform;
if (Platform.isMacOS) {
targetPlatform = TargetPlatform.iOS;
} else if (Platform.isLinux || Platform.isWindows) {
targetPlatform = TargetPlatform.android;
}
if (targetPlatform != null) {
debugDefaultTargetPlatformOverride = targetPlatform;
}
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String _projectVersion = '';
String _projectCode = '';
String _projectAppID = '';
String _projectName = '';
@override
void initState() {
_initPlatformState();
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
void _initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await GetVersion.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
String projectVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
projectVersion = await GetVersion.projectVersion;
} on PlatformException {
projectVersion = 'Failed to get project version.';
}
String projectCode;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
projectCode = await GetVersion.projectCode;
} on PlatformException {
projectCode = 'Failed to get build number.';
}
String projectAppID;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
projectAppID = await GetVersion.appID;
} on PlatformException {
projectAppID = 'Failed to get app ID.';
}
String projectName;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
projectName = await GetVersion.appName;
} on PlatformException {
projectName = 'Failed to get app name.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
_projectVersion = projectVersion;
_projectCode = projectCode;
_projectAppID = projectAppID;
_projectName = projectName;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Get Version Example'),
),
body: new SingleChildScrollView(
child: new ListBody(
children: <Widget>[
new Container(
height: 10.0,
),
new ListTile(
leading: const Icon(Icons.info),
title: const Text('Name'),
subtitle: new Text(_projectName),
),
const Divider(height: 20.0),
new ListTile(
leading: const Icon(Icons.info),
title: const Text('Running on'),
subtitle: new Text(_platformVersion),
),
const Divider(height: 20.0),
new ListTile(
leading: const Icon(Icons.info),
title: const Text('Version Name'),
subtitle: new Text(_projectVersion),
),
const Divider(height: 20.0),
new ListTile(
leading: const Icon(Icons.info),
title: const Text('Version Code'),
subtitle: new Text(_projectCode),
),
const Divider(height: 20.0),
new ListTile(
leading: const Icon(Icons.info),
title: const Text('App ID'),
subtitle: new Text(_projectAppID),
),
],
),
),
),
);
}
}