Line data Source code
1 : // Copyright 2024 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_classes/herald/app_design.dart';
5 : import 'package:app_finance/_mixins/launcher_mixin.dart';
6 : import 'package:material_ui/material_ui.dart';
7 : import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
8 :
9 : class MarkdownBuilderWrapper extends StatelessWidget with LauncherMixin {
10 : final String url;
11 : final Widget Function(BuildContext, AsyncSnapshot<String>)? builder;
12 : final Function(String, String?, String)? onTapLink;
13 :
14 0 : const MarkdownBuilderWrapper({
15 : super.key,
16 : required this.url,
17 : this.builder,
18 : this.onTapLink,
19 : });
20 :
21 0 : _openURL(_, url, __) {
22 0 : if (url != null && (url.contains('https://') || url.contains('mailto:'))) {
23 0 : openURL(url);
24 : }
25 : }
26 :
27 0 : @override
28 : Widget build(BuildContext context) {
29 0 : return FutureBuilder(
30 0 : future: DefaultAssetBundle.of(context).loadString(url),
31 0 : builder: builder ??
32 0 : (BuildContext context, AsyncSnapshot<String> snapshot) {
33 0 : if (snapshot.hasData) {
34 0 : return Directionality(
35 0 : textDirection: AppDesign.getAlignment<TextDirection>(),
36 0 : child: Markdown(
37 0 : data: (snapshot.data ?? '').replaceAll('../images', 'resource:assets/images'),
38 0 : onTapLink: onTapLink ?? _openURL),
39 : );
40 : }
41 0 : return Container();
42 : },
43 : );
44 : }
45 : }
|