Skip to content

Commit 84de2fe

Browse files
committed
update example
1 parent dd0bec2 commit 84de2fe

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

example/code.dart

+35-17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CodeViewWidget extends StatefulWidget {
1818

1919
class CodeViewState extends State<CodeViewWidget> {
2020
String? code;
21+
late bool loading;
2122

2223
@override
2324
void initState() {
@@ -26,8 +27,15 @@ class CodeViewState extends State<CodeViewWidget> {
2627
}
2728

2829
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+
});
3139
}
3240

3341
@override
@@ -36,23 +44,33 @@ class CodeViewState extends State<CodeViewWidget> {
3644
appBar: const CustomAppBar(),
3745
body: ConstraintLayout(
3846
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,
4669
),
4770
),
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+
)
5674
],
5775
),
5876
);

0 commit comments

Comments
 (0)