Skip to content

Commit 663fb3d

Browse files
authored
fix: exchange html widget library (#1360)
1 parent 1927bfa commit 663fb3d

File tree

5 files changed

+95
-117
lines changed

5 files changed

+95
-117
lines changed

lib/common/view/audio_page_header_html_description.dart

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import 'ui_constants.dart';
2-
import '../../extensions/build_context_x.dart';
31
import 'package:flutter/material.dart';
4-
import 'package:flutter_html/flutter_html.dart';
5-
import 'package:url_launcher/url_launcher.dart';
62
import 'package:yaru/yaru.dart';
73

4+
import '../../extensions/build_context_x.dart';
85
import '../../extensions/theme_data_x.dart';
6+
import 'html_text.dart';
7+
import 'ui_constants.dart';
98

109
class AudioPageHeaderHtmlDescription extends StatelessWidget {
1110
const AudioPageHeaderHtmlDescription({
@@ -38,27 +37,7 @@ class AudioPageHeaderHtmlDescription extends StatelessWidget {
3837
descriptionStyle: descriptionStyle,
3938
),
4039
),
41-
child: Html(
42-
data: description,
43-
onAnchorTap: (url, attributes, element) {
44-
if (url == null) return;
45-
launchUrl(Uri.parse(url));
46-
},
47-
style: {
48-
'img': Style(display: Display.none),
49-
'body': Style(
50-
height: Height.auto(),
51-
margin: Margins.zero,
52-
padding: HtmlPaddings.zero,
53-
textOverflow: TextOverflow.ellipsis,
54-
maxLines: 4,
55-
textAlign: TextAlign.center,
56-
fontSize: FontSize(descriptionStyle?.fontSize ?? 10),
57-
fontWeight: descriptionStyle?.fontWeight,
58-
fontFamily: descriptionStyle?.fontFamily,
59-
),
60-
},
61-
),
40+
child: HtmlText(text: description, wrapInFakeScroll: true),
6241
),
6342
),
6443
);
@@ -89,24 +68,12 @@ class _HtmlDialog extends StatelessWidget {
8968
children: [
9069
SizedBox(
9170
width: 400,
92-
child: Html(
93-
data: description,
94-
onAnchorTap: (url, attributes, element) {
95-
if (url == null) return;
96-
launchUrl(Uri.parse(url));
97-
},
98-
style: {
99-
'img': Style(display: Display.none),
100-
'body': Style(
101-
height: Height.auto(),
102-
textOverflow: TextOverflow.ellipsis,
103-
maxLines: 400,
104-
textAlign: TextAlign.center,
105-
fontSize: FontSize(descriptionStyle?.fontSize ?? 10),
106-
fontWeight: descriptionStyle?.fontWeight,
107-
fontFamily: descriptionStyle?.fontFamily,
108-
),
109-
},
71+
child: Padding(
72+
padding: const EdgeInsets.all(kLargestSpace),
73+
child: HtmlText(
74+
text: description ?? '',
75+
color: context.colorScheme.onSurface,
76+
),
11077
),
11178
),
11279
],

lib/common/view/html_text.dart

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
5+
import 'package:url_launcher/url_launcher.dart';
6+
7+
import '../../extensions/build_context_x.dart';
8+
9+
class HtmlText extends StatelessWidget {
10+
const HtmlText({
11+
super.key,
12+
required this.text,
13+
this.color,
14+
this.onTapUrl,
15+
this.wrapInFakeScroll = false,
16+
});
17+
18+
final String text;
19+
final Color? color;
20+
final FutureOr<bool> Function(String)? onTapUrl;
21+
final bool wrapInFakeScroll;
22+
23+
@override
24+
Widget build(BuildContext context) {
25+
final theColor = color ?? context.colorScheme.onSurface;
26+
27+
final htmlWidget = HtmlWidget(
28+
text,
29+
onTapUrl:
30+
onTapUrl ??
31+
(url) async {
32+
await launchUrl(Uri.parse(url));
33+
return true;
34+
},
35+
textStyle: TextStyle(color: color),
36+
customStylesBuilder: (element) {
37+
return {
38+
'color': '${theColor.toHexTriplet()}',
39+
if (wrapInFakeScroll) ...{
40+
'overflow': 'hidden',
41+
'text-overflow': 'ellipsis',
42+
'width': '100%',
43+
'display': '-webkit-box',
44+
'-webkit-line-clamp': '1',
45+
'ine-clamp': '1',
46+
'-webkit-box-orient': 'vertical',
47+
},
48+
};
49+
},
50+
);
51+
52+
if (!wrapInFakeScroll) {
53+
return htmlWidget;
54+
}
55+
56+
return ScrollConfiguration(
57+
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
58+
child: SingleChildScrollView(
59+
physics: const NeverScrollableScrollPhysics(),
60+
61+
child: htmlWidget,
62+
),
63+
);
64+
}
65+
}
66+
67+
extension ColorX on Color {
68+
String toHexTriplet() =>
69+
// ignore: deprecated_member_use
70+
'#${(value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}';
71+
}

lib/podcasts/view/podcast_audio_tile.dart

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_html/flutter_html.dart';
3-
import 'package:url_launcher/url_launcher.dart';
42
import 'package:watch_it/watch_it.dart';
53
import 'package:yaru/yaru.dart';
64

75
import '../../common/data/audio.dart';
8-
import '../../common/logging.dart';
6+
import '../../common/view/html_text.dart';
97
import '../../common/view/icons.dart';
108
import '../../common/view/share_button.dart';
119
import '../../common/view/snackbars.dart';
@@ -231,63 +229,13 @@ class _Description extends StatelessWidget with WatchItMixin {
231229
bottom: kLargestSpace,
232230
),
233231
children: [
234-
SizedBox(
235-
width: 400,
236-
child: _createHtml(
237-
color: theme.colorScheme.onSurface,
238-
maxLines: 200,
239-
paddings: HtmlPaddings.zero,
240-
),
241-
),
232+
SizedBox(width: 400, child: HtmlText(text: description ?? '')),
242233
],
243234
);
244235
},
245236
);
246237
},
247-
child: _createHtml(
248-
color: theme.colorScheme.onSurface,
249-
maxLines: 5,
250-
paddings: HtmlPaddings.all(5),
251-
),
238+
child: HtmlText(text: description ?? ''),
252239
);
253240
}
254-
255-
Widget _createHtml({
256-
required Color color,
257-
int? maxLines,
258-
TextAlign? textAlign,
259-
HtmlPaddings? paddings,
260-
}) {
261-
Widget? html;
262-
try {
263-
html = Html(
264-
data: description,
265-
onAnchorTap: (url, attributes, element) {
266-
if (url == null) return;
267-
launchUrl(Uri.parse(url));
268-
},
269-
style: {
270-
'img': Style(display: Display.none),
271-
'body': Style(
272-
margin: Margins.zero,
273-
padding: paddings,
274-
color: color,
275-
textOverflow: TextOverflow.ellipsis,
276-
maxLines: maxLines,
277-
textAlign: textAlign ?? TextAlign.start,
278-
),
279-
},
280-
);
281-
} on Exception catch (_) {
282-
printMessageInDebugMode('Error parsing html');
283-
}
284-
return html ??
285-
Text(
286-
description ?? '',
287-
style: TextStyle(color: color),
288-
overflow: TextOverflow.ellipsis,
289-
maxLines: maxLines,
290-
textAlign: textAlign ?? TextAlign.start,
291-
);
292-
}
293241
}

pubspec.lock

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,6 @@ packages:
527527
url: "https://pub.dev"
528528
source: hosted
529529
version: "1.1.0"
530-
flutter_html:
531-
dependency: "direct main"
532-
description:
533-
name: flutter_html
534-
sha256: "38a2fd702ffdf3243fb7441ab58aa1bc7e6922d95a50db76534de8260638558d"
535-
url: "https://pub.dev"
536-
source: hosted
537-
version: "3.0.0"
538530
flutter_launcher_icons:
539531
dependency: "direct dev"
540532
description:
@@ -606,6 +598,14 @@ packages:
606598
description: flutter
607599
source: sdk
608600
version: "0.0.0"
601+
flutter_widget_from_html_core:
602+
dependency: "direct main"
603+
description:
604+
name: flutter_widget_from_html_core
605+
sha256: "1120ee6ed3509ceff2d55aa6c6cbc7b6b1291434422de2411b5a59364dd6ff03"
606+
url: "https://pub.dev"
607+
source: hosted
608+
version: "0.17.0"
609609
frontend_server_client:
610610
dependency: transitive
611611
description:
@@ -687,7 +687,7 @@ packages:
687687
source: hosted
688688
version: "0.4.0"
689689
html:
690-
dependency: "direct main"
690+
dependency: transitive
691691
description:
692692
name: html
693693
sha256: "6d1264f2dffa1b1101c25a91dff0dc2daee4c18e87cd8538729773c073dbf602"
@@ -814,14 +814,6 @@ packages:
814814
url: "https://pub.dev"
815815
source: hosted
816816
version: "6.0.0"
817-
list_counter:
818-
dependency: transitive
819-
description:
820-
name: list_counter
821-
sha256: c447ae3dfcd1c55f0152867090e67e219d42fe6d4f2807db4bbe8b8d69912237
822-
url: "https://pub.dev"
823-
source: hosted
824-
version: "1.0.2"
825817
listenbrainz_dart:
826818
dependency: "direct main"
827819
description:

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ dependencies:
3030
sdk: flutter
3131
flutter_cache_manager: ^3.4.1
3232
flutter_discord_rpc: ^1.0.0
33-
flutter_html: ^3.0.0-beta.2
3433
flutter_localizations:
3534
sdk: flutter
3635
flutter_markdown: ^0.7.3
3736
flutter_tabler_icons: ^1.41.0
37+
flutter_widget_from_html_core: ^0.17.0
3838
future_loading_dialog: ^0.3.0
3939
github: ^9.24.0
4040
gtk: ^2.1.0
4141
handy_window: ^0.4.0
42-
html: ^0.15.4
42+
4343
intl: ^0.20.2
4444
lastfm: ^0.0.6
4545
listenbrainz_dart: ^0.0.4

0 commit comments

Comments
 (0)