diff --git a/CHANGELOG.md b/CHANGELOG.md index 50f6f95..8841e81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.0.3 +* Intial support for checkboxes +*([#25](https://github.com/alihassan143/htmltopdfwidgets/issues/25)) ## 1.0.2 * update readme *([#20](https://github.com/alihassan143/htmltopdfwidgets/issues/20)) diff --git a/example/lib/main.dart b/example/lib/main.dart index 9da9a32..2ada066 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -40,7 +40,13 @@ const htmlText = '''

AppFlowyEditor

AppFlowy

You can also use AppFlowy Editor as a component to build your own app.

Awesome features

+

If you have questions or feedback, please submit an issue on Github or join the community along with 1000+ builders!

+

Checked Boxes

+ + + + '''; createDocument() async { diff --git a/lib/src/html_tags.dart b/lib/src/html_tags.dart index e597e67..58fba67 100644 --- a/lib/src/html_tags.dart +++ b/lib/src/html_tags.dart @@ -25,6 +25,7 @@ class HTMLTags { static const div = 'div'; static const divider = 'hr'; static const table = 'table'; + static const label = 'label'; static const tableRow = 'tr'; static const br = 'br'; static const tableheader = "th"; @@ -65,6 +66,7 @@ class HTMLTags { HTMLTags.checkbox, HTMLTags.image, HTMLTags.section, + HTMLTags.label, ]; } diff --git a/lib/src/html_to_widgets.dart b/lib/src/html_to_widgets.dart index 191d8d7..ed03225 100644 --- a/lib/src/html_to_widgets.dart +++ b/lib/src/html_to_widgets.dart @@ -5,6 +5,7 @@ import 'package:html/dom.dart' as dom; import 'package:html/parser.dart' show parse; import 'package:htmltopdfwidgets/src/attributes.dart'; import 'package:htmltopdfwidgets/src/extension/int_extensions.dart'; +import 'package:htmltopdfwidgets/src/utils/app_assets.dart'; import 'package:http/http.dart'; import '../htmltopdfwidgets.dart'; @@ -58,6 +59,8 @@ class WidgetsHTMLDecoder { final result = []; final delta = []; TextAlign? textAlign; + bool checkbox = false; + bool alreadyChecked = false; ///find dom node in and check if its element or not than convert it according to its specs for (final domNode in domNodes) { @@ -87,14 +90,38 @@ class WidgetsHTMLDecoder { delta.clear(); } + if (checkbox) { + checkbox = false; + + result.add(Row(children: [ + SvgImage( + svg: alreadyChecked + ? AppAssets.checkedIcon + : AppAssets.unCheckedIcon), + ...await _parseSpecialElements( + domNode, + type: BuiltInAttributeKey.bulletedList, + ), + ])); + alreadyChecked = false; + } else { + if (localName == HTMLTags.checkbox) { + final checked = domNode.attributes["type"]; + if (checked != null && checked == "checkbox") { + checkbox = true; + + alreadyChecked = domNode.attributes.keys.contains("checked"); + } + } + result.addAll( + await _parseSpecialElements( + domNode, + type: BuiltInAttributeKey.bulletedList, + ), + ); + } /// Handle special elements (e.g., headings, lists, images) - result.addAll( - await _parseSpecialElements( - domNode, - type: BuiltInAttributeKey.bulletedList, - ), - ); } } else if (domNode is dom.Text) { if (delta.isNotEmpty && domNode.text.trim().isNotEmpty) { diff --git a/lib/src/utils/app_assets.dart b/lib/src/utils/app_assets.dart new file mode 100644 index 0000000..221da8b --- /dev/null +++ b/lib/src/utils/app_assets.dart @@ -0,0 +1,6 @@ +class AppAssets { + static const String checkedIcon = + ''''''; + static const String unCheckedIcon = + ''''''; +} diff --git a/pubspec.yaml b/pubspec.yaml index 6b1c354..4c90f33 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: htmltopdfwidgets description: Htmlt to pdf widgets library convert html text to pdf widgets -version: 1.0.2 +version: 1.0.3 homepage: https://github.com/alihassan143/htmltopdfwidgets environment: