Skip to content

Commit 20ac7e0

Browse files
committed
Null safety migration.
1 parent 5d09d03 commit 20ac7e0

13 files changed

+140
-231
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
## [1.0.1]
1+
## [1.1.0]
2+
* Null safety migration
3+
4+
## [1.0.1]
25
* Update documentation.
36

47
## [1.0.0]

example/android/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
buildscript {
2-
ext.kotlin_version = '1.3.50'
2+
ext.kotlin_version = '1.5.0'
33
repositories {
44
google()
5-
jcenter()
5+
mavenCentral()
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.5.0'
9+
classpath 'com.android.tools.build:gradle:4.2.1'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}
1313

1414
allprojects {
1515
repositories {
1616
google()
17-
jcenter()
17+
mavenCentral()
1818
}
1919
}
2020

example/android/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/main.dart

+39-37
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ void main() {
99
}
1010

1111
class MyApp extends StatelessWidget {
12-
// This widget is the root of your application.
1312
@override
1413
Widget build(BuildContext context) {
1514
return MaterialApp(
@@ -20,7 +19,7 @@ class MyApp extends StatelessWidget {
2019
}
2120

2221
class HomePage extends StatelessWidget {
23-
final NewsAPI _newsAPI = NewsAPI("aa67d8d98c8e4ad1b4f16dbd5f3be348");
22+
final NewsAPI _newsAPI = NewsAPI("API_KEY");
2423

2524
@override
2625
Widget build(BuildContext context) {
@@ -66,8 +65,8 @@ class HomePage extends StatelessWidget {
6665
builder: (BuildContext context, AsyncSnapshot<List<Article>> snapshot) {
6766
return snapshot.connectionState == ConnectionState.done
6867
? snapshot.hasData
69-
? _buildArticleListView(snapshot.data)
70-
: _buildError(snapshot.error)
68+
? _buildArticleListView(snapshot.data!)
69+
: _buildError(snapshot.error as ApiError)
7170
: _buildProgress();
7271
});
7372
}
@@ -78,52 +77,55 @@ class HomePage extends StatelessWidget {
7877
builder: (BuildContext context, AsyncSnapshot<List<Article>> snapshot) {
7978
return snapshot.connectionState == ConnectionState.done
8079
? snapshot.hasData
81-
? _buildArticleListView(snapshot.data)
82-
: _buildError(snapshot.error)
80+
? _buildArticleListView(snapshot.data!)
81+
: _buildError(snapshot.error as ApiError)
8382
: _buildProgress();
8483
});
8584
}
8685

8786
Widget _buildArticleListView(List<Article> articles) {
8887
return ListView.builder(
89-
itemCount: articles.length,
90-
itemBuilder: (context, index) {
91-
Article article = articles[index];
92-
return Card(
93-
child: ListTile(
94-
title: Text(article.title, maxLines: 2),
95-
subtitle: Text(article.description ?? "", maxLines: 3),
96-
trailing: article.urlToImage == null
97-
? null
98-
: Image.network(article.urlToImage),
99-
),
100-
);
101-
});
88+
itemCount: articles.length,
89+
itemBuilder: (context, index) {
90+
Article article = articles[index];
91+
return Card(
92+
child: ListTile(
93+
title: Text(article.title!, maxLines: 2),
94+
subtitle: Text(article.description ?? "", maxLines: 3),
95+
trailing: article.urlToImage == null
96+
? null
97+
: Image.network(article.urlToImage!),
98+
),
99+
);
100+
},
101+
);
102102
}
103103

104104
Widget _buildSourcesTabView() {
105105
return FutureBuilder<List<Source>>(
106-
future: _newsAPI.getSources(),
107-
builder: (BuildContext context, AsyncSnapshot<List<Source>> snapshot) {
108-
return snapshot.connectionState == ConnectionState.done
109-
? snapshot.hasData
110-
? _buildSourceListView(snapshot.data)
111-
: _buildError(snapshot.error)
112-
: _buildProgress();
113-
});
106+
future: _newsAPI.getSources(),
107+
builder: (BuildContext context, AsyncSnapshot<List<Source>> snapshot) {
108+
return snapshot.connectionState == ConnectionState.done
109+
? snapshot.hasData
110+
? _buildSourceListView(snapshot.data!)
111+
: _buildError(snapshot.error as ApiError)
112+
: _buildProgress();
113+
},
114+
);
114115
}
115116

116117
Widget _buildSourceListView(List<Source> sources) {
117118
return ListView.builder(
118-
itemCount: sources.length,
119-
itemBuilder: (context, index) {
120-
return Card(
121-
child: ListTile(
122-
title: Text(sources[index].name),
123-
subtitle: Text(sources[index].description),
124-
),
125-
);
126-
});
119+
itemCount: sources.length,
120+
itemBuilder: (context, index) {
121+
return Card(
122+
child: ListTile(
123+
title: Text(sources[index].name!),
124+
subtitle: Text(sources[index].description!),
125+
),
126+
);
127+
},
128+
);
127129
}
128130

129131
Widget _buildProgress() {
@@ -143,7 +145,7 @@ class HomePage extends StatelessWidget {
143145
style: TextStyle(fontSize: 20),
144146
),
145147
SizedBox(height: 4),
146-
Text(error.message, textAlign: TextAlign.center),
148+
Text(error.message!, textAlign: TextAlign.center),
147149
],
148150
),
149151
),

example/pubspec.lock

+23-30
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,49 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.4.2"
10+
version: "2.6.1"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
1414
name: boolean_selector
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "2.0.0"
17+
version: "2.1.0"
1818
characters:
1919
dependency: transitive
2020
description:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.1.0-nullsafety"
24+
version: "1.1.0"
2525
charcode:
2626
dependency: transitive
2727
description:
2828
name: charcode
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.1.3"
31+
version: "1.2.0"
3232
clock:
3333
dependency: transitive
3434
description:
3535
name: clock
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "1.0.1"
38+
version: "1.1.0"
3939
collection:
4040
dependency: transitive
4141
description:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.15.0-nullsafety"
46-
cupertino_icons:
47-
dependency: "direct main"
48-
description:
49-
name: cupertino_icons
50-
url: "https://pub.dartlang.org"
51-
source: hosted
52-
version: "0.1.3"
45+
version: "1.15.0"
5346
fake_async:
5447
dependency: transitive
5548
description:
5649
name: fake_async
5750
url: "https://pub.dartlang.org"
5851
source: hosted
59-
version: "1.1.0"
52+
version: "1.2.0"
6053
flutter:
6154
dependency: "direct main"
6255
description: flutter
@@ -73,49 +66,49 @@ packages:
7366
name: http
7467
url: "https://pub.dartlang.org"
7568
source: hosted
76-
version: "0.12.2"
69+
version: "0.13.3"
7770
http_parser:
7871
dependency: transitive
7972
description:
8073
name: http_parser
8174
url: "https://pub.dartlang.org"
8275
source: hosted
83-
version: "3.1.4"
76+
version: "4.0.0"
8477
matcher:
8578
dependency: transitive
8679
description:
8780
name: matcher
8881
url: "https://pub.dartlang.org"
8982
source: hosted
90-
version: "0.12.9"
83+
version: "0.12.10"
9184
meta:
9285
dependency: transitive
9386
description:
9487
name: meta
9588
url: "https://pub.dartlang.org"
9689
source: hosted
97-
version: "1.3.0-nullsafety"
90+
version: "1.3.0"
9891
news_api_flutter_package:
9992
dependency: "direct main"
10093
description:
10194
path: ".."
10295
relative: true
10396
source: path
104-
version: "1.0.0"
97+
version: "1.0.1"
10598
path:
10699
dependency: transitive
107100
description:
108101
name: path
109102
url: "https://pub.dartlang.org"
110103
source: hosted
111-
version: "1.7.0"
104+
version: "1.8.0"
112105
pedantic:
113106
dependency: transitive
114107
description:
115108
name: pedantic
116109
url: "https://pub.dartlang.org"
117110
source: hosted
118-
version: "1.9.2"
111+
version: "1.11.0"
119112
sky_engine:
120113
dependency: transitive
121114
description: flutter
@@ -127,55 +120,55 @@ packages:
127120
name: source_span
128121
url: "https://pub.dartlang.org"
129122
source: hosted
130-
version: "1.7.0"
123+
version: "1.8.1"
131124
stack_trace:
132125
dependency: transitive
133126
description:
134127
name: stack_trace
135128
url: "https://pub.dartlang.org"
136129
source: hosted
137-
version: "1.9.5"
130+
version: "1.10.0"
138131
stream_channel:
139132
dependency: transitive
140133
description:
141134
name: stream_channel
142135
url: "https://pub.dartlang.org"
143136
source: hosted
144-
version: "2.0.0"
137+
version: "2.1.0"
145138
string_scanner:
146139
dependency: transitive
147140
description:
148141
name: string_scanner
149142
url: "https://pub.dartlang.org"
150143
source: hosted
151-
version: "1.0.5"
144+
version: "1.1.0"
152145
term_glyph:
153146
dependency: transitive
154147
description:
155148
name: term_glyph
156149
url: "https://pub.dartlang.org"
157150
source: hosted
158-
version: "1.1.0"
151+
version: "1.2.0"
159152
test_api:
160153
dependency: transitive
161154
description:
162155
name: test_api
163156
url: "https://pub.dartlang.org"
164157
source: hosted
165-
version: "0.2.18"
158+
version: "0.3.0"
166159
typed_data:
167160
dependency: transitive
168161
description:
169162
name: typed_data
170163
url: "https://pub.dartlang.org"
171164
source: hosted
172-
version: "1.3.0-nullsafety"
165+
version: "1.3.0"
173166
vector_math:
174167
dependency: transitive
175168
description:
176169
name: vector_math
177170
url: "https://pub.dartlang.org"
178171
source: hosted
179-
version: "2.1.0-nullsafety"
172+
version: "2.1.0"
180173
sdks:
181-
dart: ">=2.9.0-18.0 <2.9.0"
174+
dart: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)