-
Notifications
You must be signed in to change notification settings - Fork 532
Expand file tree
/
Copy pathmain.dart
More file actions
146 lines (129 loc) Β· 4.09 KB
/
Copy pathmain.dart
File metadata and controls
146 lines (129 loc) Β· 4.09 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import 'package:epub_view/epub_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show SystemChrome, SystemUiOverlayStyle;
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
void initState() {
WidgetsBinding.instance.addObserver(this);
super.initState();
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangePlatformBrightness() {
_setSystemUIOverlayStyle();
}
Brightness get platformBrightness =>
MediaQueryData.fromView(View.of(context)).platformBrightness;
void _setSystemUIOverlayStyle() {
if (platformBrightness == Brightness.light) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
systemNavigationBarColor: Colors.grey[50],
systemNavigationBarIconBrightness: Brightness.dark,
));
} else {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarBrightness: Brightness.dark,
statusBarIconBrightness: Brightness.light,
systemNavigationBarColor: Colors.grey[850],
systemNavigationBarIconBrightness: Brightness.light,
));
}
}
@override
Widget build(BuildContext context) => MaterialApp(
title: 'Epub demo',
theme: ThemeData(
primarySwatch: Colors.blue,
brightness: Brightness.light,
),
darkTheme: ThemeData(
primarySwatch: Colors.blue,
brightness: Brightness.dark,
),
debugShowCheckedModeBanner: false,
home: const MyHomePage(),
);
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late EpubController _epubReaderController;
@override
void initState() {
_epubReaderController = EpubController(
document:
// EpubDocument.openAsset('assets/New-Findings-on-Shirdi-Sai-Baba.epub'),
EpubDocument.openAsset('assets/New-Findings-on-Shirdi-Sai-Baba.epub'),
// epubCfi:
// 'epubcfi(/6/26[id4]!/4/2/2[id4]/22)', // book.epub Chapter 3 paragraph 10
// epubCfi:
// 'epubcfi(/6/6[chapter-2]!/4/2/1612)', // book_2.epub Chapter 16 paragraph 3
);
super.initState();
}
@override
void dispose() {
_epubReaderController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: EpubViewActualChapter(
controller: _epubReaderController,
builder: (chapterValue) => Text(
chapterValue?.chapter?.Title?.replaceAll('\n', '').trim() ?? '',
textAlign: TextAlign.start,
),
),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.save_alt),
color: Colors.white,
onPressed: () => _showCurrentEpubCfi(context),
),
],
),
drawer: Drawer(
child: EpubViewTableOfContents(controller: _epubReaderController),
),
body: EpubView(
builders: EpubViewBuilders<DefaultBuilderOptions>(
options: const DefaultBuilderOptions(),
chapterDividerBuilder: (_) => const Divider(),
),
controller: _epubReaderController,
),
);
void _showCurrentEpubCfi(context) {
final cfi = _epubReaderController.generateEpubCfi();
if (cfi != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(cfi),
action: SnackBarAction(
label: 'GO',
onPressed: () {
_epubReaderController.gotoEpubCfi(cfi);
},
),
),
);
}
}
}