main.dart
3.62 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
import 'package:flutter/material.dart';
import 'package:markdown_to_pdf/markdown_to_pdf.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
import 'package:tex_markdown/tex_markdown.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ThemeMode _themeMode = ThemeMode.light;
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
themeMode: _themeMode,
theme: ThemeData(
useMaterial3: true,
brightness: Brightness.light,
colorSchemeSeed: Colors.blue,
),
darkTheme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: Colors.blue,
),
home: MyHomePage(
title: 'Flutter Demo Home Page',
onPressed: () {
setState(() {
_themeMode = ThemeMode.values[(_themeMode.index + 1) % 2];
});
},
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title, required this.onPressed});
final VoidCallback? onPressed;
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final TextEditingController _controller = TextEditingController(text: r'''

---
- unordered list
(x) Radio checked
() Radio unchecked
[x] checkbox checked
[] Checkbox unchecked
| Name | Country |
| Name | Bangladesh |
$x^w$
''');
GlobalKey globalKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
actions: [
IconButton(
onPressed: widget.onPressed,
icon: const Icon(Icons.sunny),
),
IconButton(
onPressed: () async {
var pdf = await MarkdownToPdf(
globalKey.currentContext!,
).toPdf();
// ignore: use_build_context_synchronously
showDialog(
context: context,
builder: (context) {
return Dialog(
child: ListView(
children: [
AspectRatio(
aspectRatio: 210 / 229,
child: SfPdfViewer.memory(
pdf,
),
)
],
),
);
},
);
},
icon: const Icon(Icons.toc),
),
],
),
body: Column(
children: [
Expanded(
child: RepaintBoundary(
key: globalKey,
child: AnimatedBuilder(
animation: _controller,
builder: (context, _) {
return TexMarkdown(_controller.text);
},
),
),
),
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 200),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(), label: Text("Type here:")),
maxLines: null,
controller: _controller,
),
),
),
],
),
);
}
}