I have a flutter blog application, and i am using this package to render the blog HTML content, I want this content to be selectable, I know of the SelectableText()
widget, but this cant be used to render HTML.
Anyone has an idea how I can make my HTML text selectable from mobile?
Several hours ago, in flutter_html merged to master commit that solves this problem. Right not you can import plugin to your project like this:
flutter_html:
git:
url: git://github.com/Sub6Resources/flutter_html.git
ref: master
Maybe for the time you are reading this post, the last changes will be published to pub.dev
Then, use SelectableHtml instead of Html:
SelectableHtml(
data: menuButton.content ?? "",
style: {
"body": Style(
margin: EdgeInsets.zero,
color: Theme.of(context).primaryColor,
),
},
onLinkTap: (link, renderContext, map, element) async {
if (link != null && link.isNotEmpty) {
await launch(link);
}
},
)
Edit - It is now possible without any workarounds. Use K.Amanov's answer.
I achieved this using flutter_markdown and html2md packages. Not an ideal solution as markdown doesn't support all html tags.
import 'package:html2md/html2md.dart' as html2md;
import 'package:flutter_markdown/flutter_markdown.dart';
...
...
MarkdownBody(
selectable: true,
data: html2md.convert(
'Your HTML Text here',
),
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With