This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
/
main.dart
66 lines (61 loc) · 2.25 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
import 'package:flutter/material.dart';
import 'package:flutter_sodium/flutter_sodium.dart';
import 'toc.dart';
import 'topic_page.dart';
void main() {
Sodium.init();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'flutter_sodium',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('flutter_sodium'),
),
body: SafeArea(
child: FutureBuilder(
// build table of contents
future: buildToc(context),
builder: (BuildContext context,
AsyncSnapshot<List<Topic>> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return snapshot.hasError
? Text("Build TOC failed\n\n${snapshot.error}")
: ListView(children: <Widget>[
if (snapshot.hasData)
for (var topic in snapshot.data!)
if (topic is Section)
ListTile(
title: Text(topic.title,
style: Theme.of(context)
.textTheme
.headline6))
else
ListTile(
title: Text(topic.title),
trailing: Icon(Icons.arrow_forward_ios,
size: 12.0),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
TopicPage(topic))))
]);
}
return Container();
})));
}
}