Skip to content

Commit 20c074f

Browse files
committed
Migrated to Flutter 2 null safety (some assumptions were made about what was nullable)
1 parent c3fa4ea commit 20c074f

18 files changed

+315
-182
lines changed

example/pubspec.lock

+92-31
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,63 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.3.0"
10+
version: "2.5.0"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
1414
name: boolean_selector
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "1.0.5"
17+
version: "2.1.0"
18+
characters:
19+
dependency: transitive
20+
description:
21+
name: characters
22+
url: "https://pub.dartlang.org"
23+
source: hosted
24+
version: "1.1.0"
1825
charcode:
1926
dependency: transitive
2027
description:
2128
name: charcode
2229
url: "https://pub.dartlang.org"
2330
source: hosted
24-
version: "1.1.2"
31+
version: "1.2.0"
32+
clock:
33+
dependency: transitive
34+
description:
35+
name: clock
36+
url: "https://pub.dartlang.org"
37+
source: hosted
38+
version: "1.1.0"
2539
collection:
2640
dependency: transitive
2741
description:
2842
name: collection
2943
url: "https://pub.dartlang.org"
3044
source: hosted
31-
version: "1.14.11"
45+
version: "1.15.0"
3246
contentful_rich_text:
3347
dependency: "direct main"
3448
description:
3549
path: ".."
3650
relative: true
3751
source: path
38-
version: "0.1.1"
52+
version: "0.1.2"
3953
cupertino_icons:
4054
dependency: "direct main"
4155
description:
4256
name: cupertino_icons
4357
url: "https://pub.dartlang.org"
4458
source: hosted
45-
version: "0.1.2"
59+
version: "1.0.3"
60+
fake_async:
61+
dependency: transitive
62+
description:
63+
name: fake_async
64+
url: "https://pub.dartlang.org"
65+
source: hosted
66+
version: "1.2.0"
4667
flutter:
4768
dependency: "direct main"
4869
description: flutter
@@ -53,48 +74,53 @@ packages:
5374
description: flutter
5475
source: sdk
5576
version: "0.0.0"
77+
flutter_web_plugins:
78+
dependency: transitive
79+
description: flutter
80+
source: sdk
81+
version: "0.0.0"
5682
html_unescape:
5783
dependency: transitive
5884
description:
5985
name: html_unescape
6086
url: "https://pub.dartlang.org"
6187
source: hosted
62-
version: "1.0.1+2"
88+
version: "2.0.0"
89+
js:
90+
dependency: transitive
91+
description:
92+
name: js
93+
url: "https://pub.dartlang.org"
94+
source: hosted
95+
version: "0.6.3"
6396
matcher:
6497
dependency: transitive
6598
description:
6699
name: matcher
67100
url: "https://pub.dartlang.org"
68101
source: hosted
69-
version: "0.12.5"
102+
version: "0.12.10"
70103
meta:
71104
dependency: transitive
72105
description:
73106
name: meta
74107
url: "https://pub.dartlang.org"
75108
source: hosted
76-
version: "1.1.7"
109+
version: "1.3.0"
77110
path:
78111
dependency: transitive
79112
description:
80113
name: path
81114
url: "https://pub.dartlang.org"
82115
source: hosted
83-
version: "1.6.4"
84-
pedantic:
85-
dependency: transitive
86-
description:
87-
name: pedantic
88-
url: "https://pub.dartlang.org"
89-
source: hosted
90-
version: "1.8.0+1"
91-
quiver:
116+
version: "1.8.0"
117+
plugin_platform_interface:
92118
dependency: transitive
93119
description:
94-
name: quiver
120+
name: plugin_platform_interface
95121
url: "https://pub.dartlang.org"
96122
source: hosted
97-
version: "2.0.5"
123+
version: "2.0.0"
98124
sky_engine:
99125
dependency: transitive
100126
description: flutter
@@ -106,63 +132,98 @@ packages:
106132
name: source_span
107133
url: "https://pub.dartlang.org"
108134
source: hosted
109-
version: "1.5.5"
135+
version: "1.8.0"
110136
stack_trace:
111137
dependency: transitive
112138
description:
113139
name: stack_trace
114140
url: "https://pub.dartlang.org"
115141
source: hosted
116-
version: "1.9.3"
142+
version: "1.10.0"
117143
stream_channel:
118144
dependency: transitive
119145
description:
120146
name: stream_channel
121147
url: "https://pub.dartlang.org"
122148
source: hosted
123-
version: "2.0.0"
149+
version: "2.1.0"
124150
string_scanner:
125151
dependency: transitive
126152
description:
127153
name: string_scanner
128154
url: "https://pub.dartlang.org"
129155
source: hosted
130-
version: "1.0.5"
156+
version: "1.1.0"
131157
term_glyph:
132158
dependency: transitive
133159
description:
134160
name: term_glyph
135161
url: "https://pub.dartlang.org"
136162
source: hosted
137-
version: "1.1.0"
163+
version: "1.2.0"
138164
test_api:
139165
dependency: transitive
140166
description:
141167
name: test_api
142168
url: "https://pub.dartlang.org"
143169
source: hosted
144-
version: "0.2.5"
170+
version: "0.2.19"
145171
typed_data:
146172
dependency: transitive
147173
description:
148174
name: typed_data
149175
url: "https://pub.dartlang.org"
150176
source: hosted
151-
version: "1.1.6"
177+
version: "1.3.0"
152178
url_launcher:
153179
dependency: transitive
154180
description:
155181
name: url_launcher
156182
url: "https://pub.dartlang.org"
157183
source: hosted
158-
version: "5.0.2"
184+
version: "6.0.3"
185+
url_launcher_linux:
186+
dependency: transitive
187+
description:
188+
name: url_launcher_linux
189+
url: "https://pub.dartlang.org"
190+
source: hosted
191+
version: "2.0.0"
192+
url_launcher_macos:
193+
dependency: transitive
194+
description:
195+
name: url_launcher_macos
196+
url: "https://pub.dartlang.org"
197+
source: hosted
198+
version: "2.0.0"
199+
url_launcher_platform_interface:
200+
dependency: transitive
201+
description:
202+
name: url_launcher_platform_interface
203+
url: "https://pub.dartlang.org"
204+
source: hosted
205+
version: "2.0.2"
206+
url_launcher_web:
207+
dependency: transitive
208+
description:
209+
name: url_launcher_web
210+
url: "https://pub.dartlang.org"
211+
source: hosted
212+
version: "2.0.0"
213+
url_launcher_windows:
214+
dependency: transitive
215+
description:
216+
name: url_launcher_windows
217+
url: "https://pub.dartlang.org"
218+
source: hosted
219+
version: "2.0.0"
159220
vector_math:
160221
dependency: transitive
161222
description:
162223
name: vector_math
163224
url: "https://pub.dartlang.org"
164225
source: hosted
165-
version: "2.0.8"
226+
version: "2.1.0"
166227
sdks:
167-
dart: ">=2.2.2 <3.0.0"
168-
flutter: ">=0.5.6 <2.0.0"
228+
dart: ">=2.12.0 <3.0.0"
229+
flutter: ">=1.22.0"

example/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ description: A new Flutter project.
1212
# Read more about iOS versioning at
1313
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1414
version: 1.0.0+1
15+
publish_to: none
1516

1617
environment:
1718
sdk: ">=2.1.0 <3.0.0"
@@ -25,7 +26,7 @@ dependencies:
2526

2627
# The following adds the Cupertino Icons font to your application.
2728
# Use with the CupertinoIcons class for iOS style icons.
28-
cupertino_icons: ^0.1.2
29+
cupertino_icons: ^1.0.3
2930

3031
dev_dependencies:
3132
flutter_test:

lib/contentful_rich_text.dart

+14-16
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class ContentfulRichText {
8181
static Widget defaultInline(INLINES type, Inline node) => Container();
8282

8383
dynamic richTextJson;
84-
Options options;
85-
Document richTextDocument;
84+
Options? options;
85+
Document? richTextDocument;
8686

8787
ContentfulRichText(this.richTextJson, {this.options});
8888

@@ -99,28 +99,26 @@ class ContentfulRichText {
9999
singletonRenderers.renderNode = Map.from(
100100
defaultNodeRenderers.renderNodes,
101101
);
102-
if (options?.renderNode?.renderNodes != null) {
103-
singletonRenderers.renderNode.addAll(options.renderNode.renderNodes);
102+
if (options?.renderNode.renderNodes != null) {
103+
singletonRenderers.renderNode.addAll(options!.renderNode.renderNodes);
104104
}
105105
singletonRenderers.renderMark = MARKS.renderMarks(
106-
options?.renderMark?.renderMarks,
106+
options?.renderMark.renderMarks,
107107
);
108108

109109
return Container(
110-
child: nodeListToWidget(richTextDocument.content),
110+
child: nodeListToWidget(richTextDocument?.content ?? []),
111111
);
112112
}
113113
return Container();
114114
}
115115

116116
/// nodeListToWidget renders the Widget tree from the data nodes
117-
Widget nodeListToWidget(List<dynamic> nodes) {
117+
Widget nodeListToWidget(List<dynamic>? nodes) {
118118
return Column(
119119
mainAxisAlignment: MainAxisAlignment.start,
120120
crossAxisAlignment: CrossAxisAlignment.start,
121-
children: List<Widget>.from(
122-
nodes?.map<Widget>((node) => nodeToWidget(node)) ?? [],
123-
),
121+
children: nodes?.map<Widget>((node) => nodeToWidget(node)).toList() ?? [],
124122
);
125123
}
126124

@@ -131,7 +129,7 @@ class ContentfulRichText {
131129
return Text.rich(TextSpan(text: _processInlineNode(node)));
132130
} else if (Helpers.isParagraph(node) || Helpers.isHeader(node)) {
133131
// TODO: Headers don't appear to set their size properly
134-
return singletonRenderers.renderNode[node['nodeType']](
132+
return singletonRenderers.renderNode[node['nodeType']]!(
135133
node,
136134
(nodes) => List<TextSpan>.from(
137135
nodes.map(
@@ -146,7 +144,7 @@ class ContentfulRichText {
146144
// TODO: Figure what to return when passed an unrecognized node.
147145
return Container();
148146
}
149-
return singletonRenderers.renderNode[node['nodeType']](node, nextNode);
147+
return singletonRenderers.renderNode[node['nodeType']]!(node, nextNode);
150148
}
151149
}
152150

@@ -155,7 +153,7 @@ class ContentfulRichText {
155153
/// Hyperlink nodes
156154
dynamic _processInlineNode(
157155
node, {
158-
String uri,
156+
String? uri,
159157
}) {
160158
if (node['nodeType'] == 'hyperlink' || uri?.isNotEmpty == true) {
161159
// Note: Hyperlinks are nested in other blocs like Paragraphs/Headers
@@ -167,7 +165,7 @@ class ContentfulRichText {
167165
// pass uri for Hyperlink on text nodes for TapRecognizer
168166
node['data'] = {'uri': link};
169167
}
170-
return singletonRenderers.renderNode[nodeType](
168+
return singletonRenderers.renderNode[nodeType]!(
171169
node,
172170
(nodes) => nodes
173171
?.map<TextSpan>(
@@ -182,7 +180,7 @@ class ContentfulRichText {
182180
// If not a hyperlink, process as text node
183181
TextNode textNode = TextNode(node);
184182
String nodeValue = HtmlUnescape().convert(textNode.value);
185-
if (textNode.marks?.isNotEmpty == true) {
183+
if (textNode.marks.isNotEmpty) {
186184
return TextSpan(
187185
text: nodeValue,
188186
style: MARKS.getMarksTextStyles(
@@ -194,7 +192,7 @@ class ContentfulRichText {
194192
return TextSpan(text: nodeValue);
195193
}
196194

197-
Document _parseRichTextJson() {
195+
Document? _parseRichTextJson() {
198196
if (richTextJson == null || richTextJson['nodeType'] != 'document') {
199197
return null;
200198
}

lib/state/renderers.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import 'package:flutter/material.dart';
22

33
class Renderers {
4-
Map<dynamic, Function> renderNode;
5-
Map<dynamic, TextStyle> renderMark;
4+
late Map<dynamic, Function> renderNode;
5+
late Map<dynamic, TextStyle> renderMark;
66
}
77

88
Renderers singletonRenderers = Renderers();

0 commit comments

Comments
 (0)