Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.79k stars 860 forks source link

The package must export html/dom to satisfy onLinkTap being acceptable #1178

Open darkstarx opened 1 year ago

darkstarx commented 1 year ago
typedef OnTap = void Function(
  String? url,
  RenderContext context,
  Map<String, String> attributes,
  dom.Element? element,
);
...
  /// A function that defines what to do when a link is tapped
  final OnTap? onLinkTap;

Dart allow to use methods but not only closures in functional properties. So I can write such code

Html(
  data: snapshot.data,
  style: htmlStyle,
  onLinkTap: onLinkType,
),
...
void onLinkType(
  String? url,
  RenderContext context,
  Map<String, String> attributes,
  dom.Element? element,
) {
...
}

And I have to put the html dependency in my project's pubspec.yaml just to be able to use method instead of closure. That's unacceptable. This is the same mistake as the one described here https://dart-lang.github.io/linter/lints/library_private_types_in_public_api.html

As a solution you can write export 'package:html/dom.dart' as dom; in the flutter_html.dart.

erickok commented 1 year ago

"That's unacceptable." is a bit harsh but you point is certainly valid and it's great you gave the solution. If you want you can make a PR or not and we will take care of it.