File tree 1 file changed +35
-17
lines changed
1 file changed +35
-17
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ class CodeViewWidget extends StatefulWidget {
18
18
19
19
class CodeViewState extends State <CodeViewWidget > {
20
20
String ? code;
21
+ late bool loading;
21
22
22
23
@override
23
24
void initState () {
@@ -26,8 +27,15 @@ class CodeViewState extends State<CodeViewWidget> {
26
27
}
27
28
28
29
void loadCode () async {
29
- code = await rootBundle.loadString (widget.codePath);
30
- setState (() {});
30
+ setState (() {
31
+ loading = true ;
32
+ });
33
+ try {
34
+ code = await rootBundle.loadString (widget.codePath);
35
+ } catch (_) {}
36
+ setState (() {
37
+ loading = false ;
38
+ });
31
39
}
32
40
33
41
@override
@@ -36,23 +44,33 @@ class CodeViewState extends State<CodeViewWidget> {
36
44
appBar: const CustomAppBar (),
37
45
body: ConstraintLayout (
38
46
children: [
39
- SingleChildScrollView (
40
- child: Padding (
41
- child: Text (
42
- code ?? '' ,
43
- style: const TextStyle (
44
- color: Colors .black,
45
- fontSize: 16 ,
47
+ if (loading)
48
+ const CircularProgressIndicator ().applyConstraint (
49
+ size: 30 ,
50
+ centerTo: parent,
51
+ ),
52
+ if (! loading && code == null )
53
+ const Text ('Code loading failed' ).applyConstraint (
54
+ centerTo: parent,
55
+ ),
56
+ if (code != null )
57
+ SingleChildScrollView (
58
+ child: Padding (
59
+ child: Text (
60
+ code ?? '' ,
61
+ style: const TextStyle (
62
+ color: Colors .black,
63
+ fontSize: 16 ,
64
+ ),
65
+ ),
66
+ padding: const EdgeInsets .only (
67
+ left: 20 ,
68
+ top: 20 ,
46
69
),
47
70
),
48
- padding: const EdgeInsets .only (
49
- left: 20 ,
50
- top: 20 ,
51
- ),
52
- ),
53
- ).applyConstraint (
54
- size: matchParent,
55
- )
71
+ ).applyConstraint (
72
+ size: matchParent,
73
+ )
56
74
],
57
75
),
58
76
);
You can’t perform that action at this time.
0 commit comments