From 44cd9a6b8202ae55bbc263cebe7ebe8eba072b14 Mon Sep 17 00:00:00 2001 From: Jacob Wrenn Date: Mon, 8 Jun 2020 11:32:34 +0100 Subject: [PATCH 1/3] add support for list style position --- lib/html_parser.dart | 68 +++++++++++++++++++++++++++++--------------- lib/style.dart | 19 +++++++++++++ 2 files changed, 64 insertions(+), 23 deletions(-) diff --git a/lib/html_parser.dart b/lib/html_parser.dart index da6601b887..319742e022 100644 --- a/lib/html_parser.dart +++ b/lib/html_parser.dart @@ -253,35 +253,57 @@ class HtmlParser extends StatelessWidget { ), ); } else if (tree.style?.display == Display.LIST_ITEM) { + List children; + if (tree.style?.listStylePosition == ListStylePosition.OUTSIDE) { + children = [ + PositionedDirectional( + width: 30, //TODO derive this from list padding. + start: 0, + child: Text('${newContext.style.markerContent}\t', + textAlign: TextAlign.right, + style: newContext.style.generateTextStyle()), + ), + Padding( + padding: + EdgeInsets.only(left: 30), //TODO derive this from list padding. + child: StyledText( + textSpan: TextSpan( + children: tree.children + ?.map((tree) => parseTree(newContext, tree)) + ?.toList() ?? + [], + style: newContext.style.generateTextStyle(), + ), + style: newContext.style, + ), + ) + ]; + } else if (tree.style?.listStylePosition == ListStylePosition.INSIDE) { + children = [ + Padding( + padding: + EdgeInsets.only(left: 30), //TODO derive this from list padding. + child: StyledText( + textSpan: TextSpan( + text: '${newContext.style.markerContent}\t', + children: tree.children + ?.map((tree) => parseTree(newContext, tree)) + ?.toList() ?? + [], + style: newContext.style.generateTextStyle(), + ), + style: newContext.style, + ), + ) + ]; + } return WidgetSpan( child: ContainerSpan( newContext: newContext, style: tree.style, shrinkWrap: context.parser.shrinkWrap, child: Stack( - children: [ - PositionedDirectional( - width: 30, //TODO derive this from list padding. - start: 0, - child: Text('${newContext.style.markerContent}\t', - textAlign: TextAlign.right, - style: newContext.style.generateTextStyle()), - ), - Padding( - padding: EdgeInsets.only( - left: 30), //TODO derive this from list padding. - child: StyledText( - textSpan: TextSpan( - children: tree.children - ?.map((tree) => parseTree(newContext, tree)) - ?.toList() ?? - [], - style: newContext.style.generateTextStyle(), - ), - style: newContext.style, - ), - ) - ], + children: children, ), ), ); diff --git a/lib/style.dart b/lib/style.dart index a7c81c33ba..ff1d0c998a 100644 --- a/lib/style.dart +++ b/lib/style.dart @@ -77,6 +77,12 @@ class Style { /// Default: ListStyleType.DISC ListStyleType listStyleType; + /// CSS attribute "`list-style-position`" + /// + /// Inherited: yes, + /// Default: ListStylePosition.OUTSIDE + ListStylePosition listStylePosition; + /// CSS attribute "`padding`" /// /// Inherited: no, @@ -172,6 +178,7 @@ class Style { this.height, this.letterSpacing, this.listStyleType, + this.listStylePosition, this.padding, this.margin, this.textAlign, @@ -194,6 +201,9 @@ class Style { (display == Display.BLOCK || display == Display.LIST_ITEM)) { this.alignment = Alignment.centerLeft; } + if (this.listStylePosition == null && display == Display.LIST_ITEM) { + this.listStylePosition = ListStylePosition.OUTSIDE; + } } TextStyle generateTextStyle() { @@ -239,6 +249,7 @@ class Style { height: other.height, letterSpacing: other.letterSpacing, listStyleType: other.listStyleType, + listStylePosition: other.listStylePosition, padding: other.padding, //TODO merge EdgeInsets margin: other.margin, @@ -276,6 +287,7 @@ class Style { fontWeight: child.fontWeight ?? fontWeight, letterSpacing: child.letterSpacing ?? letterSpacing, listStyleType: child.listStyleType ?? listStyleType, + listStylePosition: child.listStylePosition ?? listStylePosition, textAlign: child.textAlign ?? textAlign, textShadow: child.textShadow ?? textShadow, whiteSpace: child.whiteSpace ?? whiteSpace, @@ -296,6 +308,7 @@ class Style { double height, double letterSpacing, ListStyleType listStyleType, + ListStylePosition listStylePosition, EdgeInsets padding, EdgeInsets margin, TextAlign textAlign, @@ -327,6 +340,7 @@ class Style { height: height ?? this.height, letterSpacing: letterSpacing ?? this.letterSpacing, listStyleType: listStyleType ?? this.listStyleType, + listStylePosition: listStylePosition ?? this.listStylePosition, padding: padding ?? this.padding, margin: margin ?? this.margin, textAlign: textAlign ?? this.textAlign, @@ -406,6 +420,11 @@ enum ListStyleType { DECIMAL, } +enum ListStylePosition { + OUTSIDE, + INSIDE, +} + enum VerticalAlign { BASELINE, SUB, From 3e33f722f410c369c769e44a828a5789e67adb6d Mon Sep 17 00:00:00 2001 From: Jacob Wrenn Date: Sat, 20 Jun 2020 12:04:11 +0100 Subject: [PATCH 2/3] make requested changes --- lib/html_parser.dart | 73 +++++++++++++++++--------------------------- lib/style.dart | 3 -- 2 files changed, 28 insertions(+), 48 deletions(-) diff --git a/lib/html_parser.dart b/lib/html_parser.dart index 319742e022..80cc5d5093 100644 --- a/lib/html_parser.dart +++ b/lib/html_parser.dart @@ -253,57 +253,40 @@ class HtmlParser extends StatelessWidget { ), ); } else if (tree.style?.display == Display.LIST_ITEM) { - List children; - if (tree.style?.listStylePosition == ListStylePosition.OUTSIDE) { - children = [ - PositionedDirectional( - width: 30, //TODO derive this from list padding. - start: 0, - child: Text('${newContext.style.markerContent}\t', - textAlign: TextAlign.right, - style: newContext.style.generateTextStyle()), - ), - Padding( - padding: - EdgeInsets.only(left: 30), //TODO derive this from list padding. - child: StyledText( - textSpan: TextSpan( - children: tree.children - ?.map((tree) => parseTree(newContext, tree)) - ?.toList() ?? - [], - style: newContext.style.generateTextStyle(), - ), - style: newContext.style, - ), - ) - ]; - } else if (tree.style?.listStylePosition == ListStylePosition.INSIDE) { - children = [ - Padding( - padding: - EdgeInsets.only(left: 30), //TODO derive this from list padding. - child: StyledText( - textSpan: TextSpan( - text: '${newContext.style.markerContent}\t', - children: tree.children - ?.map((tree) => parseTree(newContext, tree)) - ?.toList() ?? - [], - style: newContext.style.generateTextStyle(), - ), - style: newContext.style, - ), - ) - ]; - } return WidgetSpan( child: ContainerSpan( newContext: newContext, style: tree.style, shrinkWrap: context.parser.shrinkWrap, child: Stack( - children: children, + children: [ + if (tree.style?.listStylePosition == ListStylePosition.OUTSIDE || tree.style?.listStylePosition == null) + PositionedDirectional( + width: 30, //TODO derive this from list padding. + start: 0, + child: Text('${newContext.style.markerContent}\t', + textAlign: TextAlign.right, + style: newContext.style.generateTextStyle()), + ), + Padding( + padding: EdgeInsets.only( + left: 30), //TODO derive this from list padding. + child: StyledText( + textSpan: TextSpan( + text: (tree.style?.listStylePosition == + ListStylePosition.INSIDE) + ? '${newContext.style.markerContent}\t' + : null, + children: tree.children + ?.map((tree) => parseTree(newContext, tree)) + ?.toList() ?? + [], + style: newContext.style.generateTextStyle(), + ), + style: newContext.style, + ), + ) + ], ), ), ); diff --git a/lib/style.dart b/lib/style.dart index ff1d0c998a..c387982214 100644 --- a/lib/style.dart +++ b/lib/style.dart @@ -201,9 +201,6 @@ class Style { (display == Display.BLOCK || display == Display.LIST_ITEM)) { this.alignment = Alignment.centerLeft; } - if (this.listStylePosition == null && display == Display.LIST_ITEM) { - this.listStylePosition = ListStylePosition.OUTSIDE; - } } TextStyle generateTextStyle() { From 6bda639841a29ad90a7bb530d6adb5bed51ede30 Mon Sep 17 00:00:00 2001 From: Jacob Wrenn Date: Wed, 12 Aug 2020 15:16:22 +0100 Subject: [PATCH 3/3] increase version of svg --- pubspec.lock | 96 ++++++++++++++++++++++------------------------------ pubspec.yaml | 2 +- 2 files changed, 42 insertions(+), 56 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 38d864d304..d7e61f1a99 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,41 +1,34 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.13" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.6.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.1" + version: "2.5.0-nullsafety" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0-nullsafety.2" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" + version: "1.2.0-nullsafety" chewie: dependency: "direct main" description: @@ -50,13 +43,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0+1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0-nullsafety" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.12" + version: "1.15.0-nullsafety.2" convert: dependency: transitive description: @@ -64,13 +64,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" css_colors: dependency: "direct main" description: @@ -85,6 +78,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.16.1" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0-nullsafety" flutter: dependency: "direct main" description: flutter @@ -96,7 +96,7 @@ packages: name: flutter_svg url: "https://pub.dartlang.org" source: hosted - version: "0.17.4" + version: "0.18.0" flutter_test: dependency: "direct dev" description: flutter @@ -114,27 +114,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.14.0+3" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.12" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10-nullsafety" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety.2" open_iconic_flutter: dependency: transitive description: @@ -148,7 +141,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.8.0-nullsafety" path_drawing: dependency: transitive description: @@ -169,14 +162,7 @@ packages: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.3" + version: "3.1.0" screen: dependency: transitive description: @@ -195,56 +181,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0-nullsafety" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0-nullsafety" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0-nullsafety" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.15" + version: "0.2.19-nullsafety" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.2" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety.2" video_player: dependency: "direct main" description: @@ -286,7 +272,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.6.1" + version: "4.3.0" sdks: - dart: ">=2.7.0 <3.0.0" - flutter: ">=1.17.0 <2.0.0" + dart: ">=2.10.0-0.0.dev <2.10.0" + flutter: ">=1.18.0-6.0.pre <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 79d2362932..bf6c7ed91b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,7 +26,7 @@ dependencies: chewie_audio: ^1.0.0+1 # Plugins for rendering the tag. - flutter_svg: ^0.17.4 + flutter_svg: ^0.18.0 flutter: sdk: flutter