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
import 'dart:async';
import 'package:flutter/material.dart';
String message = 'Flutter Debug Loader';
String explanation = 'Please stand by...';
double progress = 0.0;
double progressMax = 0.0;
StateSetter setState = (VoidCallback fn) => fn();
Timer connectionTimeout;
void main() {
new LoaderBinding();
runApp(
new MaterialApp(
title: 'Flutter Debug Loader',
debugShowCheckedModeBanner: false,
home: new Scaffold(
body: new StatefulBuilder(
builder: (BuildContext context, StateSetter setStateRef) {
setState = setStateRef;
return new Column(
children: <Widget>[
new Expanded(
child: new Center(
child: const FlutterLogo(size: 100.0),
),
),
new Expanded(
child: new Builder(
builder: (BuildContext context) {
List<Widget> children = <Widget>[];
children.add(new Text(
message,
style: const TextStyle(fontSize: 24.0),
textAlign: TextAlign.center
));
if (progressMax >= 0.0) {
children.add(const SizedBox(height: 18.0));
children.add(new Center(child: new CircularProgressIndicator(value: progressMax > 0 ? progress / progressMax : null)));
}
return new ScrollView(children: children);
},
),
),
new Expanded(
child: new Block(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
children: <Widget>[ new Text(explanation, textAlign: TextAlign.center) ]
),
),
],
);
},
),
),
),
);
connectionTimeout = new Timer(const Duration(seconds: 8), () {
setState(() {
explanation =
'This is a hot-reload-enabled debug-mode Flutter application. '
'To launch this application, please use the "flutter run" command. '
'To be able to launch a Flutter application in debug mode from the '
'device, please use "flutter run --no-hot". To install a release '
'mode build of this application on your device, use "flutter install".';
progressMax = -1.0;
});
});
}
class LoaderBinding extends WidgetsFlutterBinding {
@override
void initServiceExtensions() {
super.initServiceExtensions();
registerStringServiceExtension(
name: 'loaderShowMessage',
getter: () => message,
setter: (String value) {
connectionTimeout?.cancel();
connectionTimeout = null;
setState(() {
message = value;
});
}
);
registerStringServiceExtension(
name: 'loaderShowExplanation',
getter: () => explanation,
setter: (String value) {
connectionTimeout?.cancel();
connectionTimeout = null;
setState(() {
explanation = value;
});
}
);
registerNumericServiceExtension(
name: 'loaderSetProgress',
getter: () => progress,
setter: (double value) {
setState(() {
progress = value;
});
}
);
registerNumericServiceExtension(
name: 'loaderSetProgressMax',
getter: () => progressMax,
setter: (double value) {
setState(() {
progressMax = value;
});
}
);
}
}