2024-01-31 05:14:23 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-03-18 07:26:54 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart' show rootBundle;
|
2024-01-31 05:14:23 +00:00
|
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
2022-05-17 20:08:28 +00:00
|
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
2021-03-18 07:26:54 +00:00
|
|
|
|
|
|
|
class BrandMarkdown extends StatefulWidget {
|
|
|
|
const BrandMarkdown({
|
|
|
|
required this.fileName,
|
2022-10-26 16:26:09 +00:00
|
|
|
super.key,
|
2022-06-05 19:36:32 +00:00
|
|
|
});
|
2021-03-18 07:26:54 +00:00
|
|
|
|
|
|
|
final String fileName;
|
|
|
|
|
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<BrandMarkdown> createState() => _BrandMarkdownState();
|
2021-03-18 07:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _BrandMarkdownState extends State<BrandMarkdown> {
|
|
|
|
String _mdContent = '';
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_loadMdFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _loadMdFile() async {
|
2022-06-05 19:36:32 +00:00
|
|
|
final String mdFromFile = await rootBundle
|
2021-03-18 07:26:54 +00:00
|
|
|
.loadString('assets/markdown/${widget.fileName}-${'locale'.tr()}.md');
|
|
|
|
setState(() {
|
|
|
|
_mdContent = mdFromFile;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) {
|
2023-03-27 17:02:44 +00:00
|
|
|
final MarkdownStyleSheet markdown = MarkdownStyleSheet();
|
2022-06-09 21:13:06 +00:00
|
|
|
return MarkdownBody(
|
2021-06-20 21:08:52 +00:00
|
|
|
shrinkWrap: true,
|
2021-03-18 07:26:54 +00:00
|
|
|
styleSheet: markdown,
|
2024-06-26 15:41:10 +00:00
|
|
|
selectable: true,
|
2022-06-05 19:36:32 +00:00
|
|
|
onTapLink: (final String text, final String? href, final String title) {
|
2021-03-18 07:26:54 +00:00
|
|
|
if (href != null) {
|
2022-06-05 19:36:32 +00:00
|
|
|
canLaunchUrlString(href).then((final bool canLaunchURL) {
|
2021-03-18 07:26:54 +00:00
|
|
|
if (canLaunchURL) {
|
2022-05-17 20:08:28 +00:00
|
|
|
launchUrlString(href);
|
2021-03-18 07:26:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data: _mdContent,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|