Skip to content

Commit 468142c

Browse files
committed
improved error handling
1 parent e338ab9 commit 468142c

File tree

7 files changed

+26
-113
lines changed

7 files changed

+26
-113
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [3.0.0-nullsafety.1] - Feb 1, 2021
2+
* Improved error handling
3+
14
## [3.0.0-nullsafety.0] - Jan 27, 2021
25

36
* Migrate to null safety

example/pubspec.lock

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ packages:
4343
url: "https://pub.dartlang.org"
4444
source: hosted
4545
version: "1.15.0-nullsafety.5"
46-
cupertino_icons:
47-
dependency: "direct main"
48-
description:
49-
name: cupertino_icons
50-
url: "https://pub.dartlang.org"
51-
source: hosted
52-
version: "1.0.2"
5346
fake_async:
5447
dependency: transitive
5548
description:
@@ -108,7 +101,7 @@ packages:
108101
path: ".."
109102
relative: true
110103
source: path
111-
version: "3.0.0-nullsafety.0"
104+
version: "3.0.0-nullsafety.1"
112105
sky_engine:
113106
dependency: transitive
114107
description: flutter

example/pubspec.yaml

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
name: example
22
description: A new Flutter project.
3-
4-
# The following defines the version and build number for your application.
5-
# A version number is three numbers separated by dots, like 1.2.43
6-
# followed by an optional build number separated by a +.
7-
# Both the version and the builder number may be overridden in flutter
8-
# build by specifying --build-name and --build-number, respectively.
9-
# In Android, build-name is used as versionName while build-number used as versionCode.
10-
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
11-
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
12-
# Read more about iOS versioning at
13-
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
143
version: 1.0.0+1
154

165
environment:
@@ -22,53 +11,9 @@ dependencies:
2211
simple_html_css:
2312
path: ../
2413

25-
# The following adds the Cupertino Icons font to your application.
26-
# Use with the CupertinoIcons class for iOS style icons.
27-
cupertino_icons: ^1.0.2
28-
2914
dev_dependencies:
3015
flutter_test:
3116
sdk: flutter
3217

33-
34-
# For information on the generic Dart part of this file, see the
35-
# following page: https://dart.dev/tools/pub/pubspec
36-
37-
# The following section is specific to Flutter.
3818
flutter:
39-
40-
# The following line ensures that the Material Icons font is
41-
# included with your application, so that you can use the icons in
42-
# the material Icons class.
43-
uses-material-design: true
44-
45-
# To add assets to your application, add an assets section, like this:
46-
# assets:
47-
# - images/a_dot_burr.jpeg
48-
# - images/a_dot_ham.jpeg
49-
50-
# An image asset can refer to one or more resolution-specific "variants", see
51-
# https://flutter.dev/assets-and-images/#resolution-aware.
52-
53-
# For details regarding adding assets from package dependencies, see
54-
# https://flutter.dev/assets-and-images/#from-packages
55-
56-
# To add custom fonts to your application, add a fonts section here,
57-
# in this "flutter" section. Each entry in this list should have a
58-
# "family" key with the font family name, and a "fonts" key with a
59-
# list giving the asset and other descriptors for the font. For
60-
# example:
61-
# fonts:
62-
# - family: Schyler
63-
# fonts:
64-
# - asset: fonts/Schyler-Regular.ttf
65-
# - asset: fonts/Schyler-Italic.ttf
66-
# style: italic
67-
# - family: Trajan Pro
68-
# fonts:
69-
# - asset: fonts/TrajanPro.ttf
70-
# - asset: fonts/TrajanPro_Bold.ttf
71-
# weight: 700
72-
#
73-
# For details regarding fonts from package dependencies,
74-
# see https://flutter.dev/custom-fonts/#from-packages
19+
uses-material-design: true

lib/simple_html_css.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ library simple_html_css;
1717
* limitations under the License.
1818
*/
1919

20-
//TODO: Migrate to null safety
21-
2220
export 'src/internals.dart';
2321
export 'src/utils.dart';
2422
export 'src/html_stylist.dart';

lib/src/html_stylist.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class HTML {
6060
{Function? linksCallback,
6161
Map<String, TextStyle>? overrideStyle,
6262
TextStyle? defaultTextStyle}) {
63-
//Validating empty content
64-
if (htmlContent.isEmpty) {
65-
return TextSpan();
66-
}
67-
6863
//to fix a known issue with &nbsp; when appearing after an ending tag
6964
htmlContent =
7065
htmlContent.replaceAll("&nbsp;", " ").replaceAll("&nbsp", " ");
@@ -76,7 +71,16 @@ class HTML {
7671
linksCallback: linksCallback,
7772
overrideStyleMap: overrideStyle ?? Map<String, TextStyle>(),
7873
defaultTextStyle: defaultTextStyle);
79-
return TextSpan(text: "", children: p.parse());
74+
75+
var list = <TextSpan>[];
76+
try {
77+
list = p.parse();
78+
} catch (e, s) {
79+
print('simple_html_css Exception: $e');
80+
print('simple_html_css Stack Trace: $s');
81+
}
82+
83+
return TextSpan(text: "", children: list);
8084
}
8185

8286
/// Returns a [RichText] widget you can directly add to your widget tree.

lib/src/internals.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,13 @@ class Parser {
314314
text: "\n",
315315
));
316316
}
317-
var top = _stack.removeLast();
318-
if (top.name != event.name) {
319-
print("Malformed HTML");
320-
return;
317+
318+
if (_stack.isNotEmpty) {
319+
var top = _stack.removeLast();
320+
if (top.name != event.name) {
321+
print("Malformed HTML");
322+
return;
323+
}
321324
}
322325
}
323326

@@ -330,7 +333,9 @@ class Parser {
330333
});
331334

332335
//removing last textSpan to avoid extra space at the bottom
333-
spans.removeLast();
336+
if (spans.isNotEmpty) {
337+
spans.removeLast();
338+
}
334339
return spans;
335340
}
336341
}

pubspec.yaml

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: simple_html_css
22
description: This package allows you to use simple HTML and inline CSS styles to style your text in flutter. A fork of css_text package.
3-
version: 3.0.0-nullsafety.0
3+
version: 3.0.0-nullsafety.1
44
homepage: https://github.com/ali-thowfeek/simple_html_css_flutter
55
repository: https://github.com/ali-thowfeek/simple_html_css_flutter
66
environment:
@@ -16,39 +16,4 @@ dev_dependencies:
1616
flutter_test:
1717
sdk: flutter
1818

19-
# For information on the generic Dart part of this file, see the
20-
# following page: https://dart.dev/tools/pub/pubspec
21-
22-
# The following section is specific to Flutter.
2319
flutter:
24-
25-
# To add assets to your package, add an assets section, like this:
26-
# assets:
27-
# - images/a_dot_burr.jpeg
28-
# - images/a_dot_ham.jpeg
29-
#
30-
# For details regarding assets in packages, see
31-
# https://flutter.dev/assets-and-images/#from-packages
32-
#
33-
# An image asset can refer to one or more resolution-specific "variants", see
34-
# https://flutter.dev/assets-and-images/#resolution-aware.
35-
36-
# To add custom fonts to your package, add a fonts section here,
37-
# in this "flutter" section. Each entry in this list should have a
38-
# "family" key with the font family name, and a "fonts" key with a
39-
# list giving the asset and other descriptors for the font. For
40-
# example:
41-
# fonts:
42-
# - family: Schyler
43-
# fonts:
44-
# - asset: fonts/Schyler-Regular.ttf
45-
# - asset: fonts/Schyler-Italic.ttf
46-
# style: italic
47-
# - family: Trajan Pro
48-
# fonts:
49-
# - asset: fonts/TrajanPro.ttf
50-
# - asset: fonts/TrajanPro_Bold.ttf
51-
# weight: 700
52-
#
53-
# For details regarding fonts in packages, see
54-
# https://flutter.dev/custom-fonts/#from-packages

0 commit comments

Comments
 (0)