-
Notifications
You must be signed in to change notification settings - Fork 10
/
ota_dialog.dart
130 lines (125 loc) · 3.95 KB
/
ota_dialog.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
import 'package:byr_mobile_app/customizations/theme_controller.dart';
import 'package:byr_mobile_app/local_objects/local_storage.dart';
import 'package:flutter/material.dart';
import 'package:ota_update/ota_update.dart';
import 'package:get/get.dart';
class OTADialog extends StatefulWidget {
final String version;
final String link;
final String updateContent;
OTADialog(this.version, this.link, {this.updateContent = " "});
@override
_OTADialogState createState() => _OTADialogState();
}
class _OTADialogState extends State<OTADialog> {
double _percentage = 0;
bool _started = false;
String _statusString = '';
ScrollController controller;
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
void initState() {
super.initState();
controller = ScrollController(initialScrollOffset: 0.5);
}
@override
Widget build(BuildContext context) {
return AlertDialog(
backgroundColor: E().dialogBackgroundColor,
title: Text("newVersion".tr + ": " + widget.version, style: TextStyle(color: E().dialogTitleColor)),
content: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 200,
child: Scrollbar(
controller: controller,
isAlwaysShown: true,
child: SingleChildScrollView(
controller: controller,
child: Container(
child: Text(
widget.updateContent,
style: TextStyle(color: E().dialogContentColor),
),
padding: EdgeInsets.all(10),
),
),
),
),
Visibility(
visible: _started,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: Text(
_statusString,
style: TextStyle(color: E().dialogContentColor),
),
padding: EdgeInsets.all(10),
),
LinearProgressIndicator(
value: _percentage + 1 / 100,
),
],
),
),
],
),
),
actions: <Widget>[
FlatButton(
child: Text("update".tr),
onPressed: () {
if (_started) {
return;
}
try {
OtaUpdate().execute(widget.link, destinationFilename: 'byr_mobile_app.apk').listen(
(OtaEvent event) {
if (event.status == OtaStatus.DOWNLOADING) {
_percentage = (int.tryParse(event.value) ?? _percentage) / 100;
if (mounted) {
setState(() {});
}
} else if (event.status == OtaStatus.INSTALLING) {
Navigator.of(context).pop();
}
},
);
_statusString = "downloadImageTrans".tr;
_started = true;
if (mounted) {
setState(() {});
}
} catch (e) {
_statusString = "fail".tr;
if (mounted) {
setState(() {});
}
}
},
),
FlatButton(
child: Text("ignoreVersion".tr),
onPressed: () {
LocalStorage.setIgnoreVersion(widget.version);
Navigator.of(context).pop();
},
),
FlatButton(
child: Text(_started ? "minimizeTrans".tr : "cancelTrans".tr),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
}
}