forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown_viewer.dart
More file actions
76 lines (71 loc) · 2.63 KB
/
Copy pathmarkdown_viewer.dart
File metadata and controls
76 lines (71 loc) · 2.63 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
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:omi/backend/preferences.dart';
class MarkdownViewer extends StatefulWidget {
final String markdown;
final String title;
const MarkdownViewer({super.key, required this.markdown, required this.title});
@override
State<MarkdownViewer> createState() => _MarkdownViewerState();
}
class _MarkdownViewerState extends State<MarkdownViewer> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: Theme.of(context).colorScheme.primary, title: Text(widget.title)),
backgroundColor: Theme.of(context).colorScheme.primary,
body: ListView(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(left: 16.0, right: 24),
child: MarkdownBody(
shrinkWrap: true,
styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context)).copyWith(
a: const TextStyle(fontSize: 18, height: 1.2),
p: const TextStyle(fontSize: 16, height: 1.2),
blockquote: const TextStyle(
fontSize: 16,
height: 1.2,
backgroundColor: Colors.transparent,
color: Colors.black,
),
blockquoteDecoration: BoxDecoration(
color: const Color(0xFF35343B),
borderRadius: BorderRadius.circular(4),
),
code: const TextStyle(
fontSize: 16,
height: 1.2,
backgroundColor: Colors.transparent,
decoration: TextDecoration.none,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
data: widget.markdown,
imageBuilder: (uri, title, alt) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Image.network(uri.toString()),
);
// return Container();
},
onTapLink: (text, href, title) {
if (href != null) {
if (href.contains('?')) {
href += '&uid=${SharedPreferencesUtil().uid}';
} else {
href += '?uid=${SharedPreferencesUtil().uid}';
}
launchUrl(Uri.parse(href));
}
},
),
),
],
),
);
}
}