mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-10 10:00:00 +00:00
56 lines
1.4 KiB
Dart
56 lines
1.4 KiB
Dart
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart' show rootBundle;
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
|
|
|
class BrandMarkdown extends StatefulWidget {
|
|
const BrandMarkdown({
|
|
required this.fileName,
|
|
super.key,
|
|
});
|
|
|
|
final String fileName;
|
|
|
|
@override
|
|
State<BrandMarkdown> createState() => _BrandMarkdownState();
|
|
}
|
|
|
|
class _BrandMarkdownState extends State<BrandMarkdown> {
|
|
String _mdContent = '';
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadMdFile();
|
|
}
|
|
|
|
void _loadMdFile() async {
|
|
final String mdFromFile = await rootBundle
|
|
.loadString('assets/markdown/${widget.fileName}-${'locale'.tr()}.md');
|
|
setState(() {
|
|
_mdContent = mdFromFile;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(final BuildContext context) {
|
|
final MarkdownStyleSheet markdown = MarkdownStyleSheet();
|
|
return MarkdownBody(
|
|
shrinkWrap: true,
|
|
styleSheet: markdown,
|
|
selectable: true,
|
|
onTapLink: (final String text, final String? href, final String title) {
|
|
if (href != null) {
|
|
canLaunchUrlString(href).then((final bool canLaunchURL) {
|
|
if (canLaunchURL) {
|
|
launchUrlString(href);
|
|
}
|
|
});
|
|
}
|
|
},
|
|
data: _mdContent,
|
|
);
|
|
}
|
|
}
|