Skip to content

Commit 48bc239

Browse files
committed
NNBD example
1 parent efd759c commit 48bc239

File tree

12 files changed

+139
-147
lines changed

12 files changed

+139
-147
lines changed

example/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:pedantic/analysis_options.1.9.0.yaml
1+
include: package:pedantic/analysis_options.1.11.0.yaml
22
linter:
33
rules:
44
- prefer_final_locals

example/lib/data/api.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'dart:convert';
22

33
import 'package:built_collection/built_collection.dart';
44
import 'package:http/http.dart' as http;
5-
import 'package:meta/meta.dart';
65

76
import 'comment.dart';
87
import 'serializers.dart';
@@ -17,20 +16,17 @@ class Api {
1716
Stream<BuiltList<Comment>> getComments() async* {
1817
_logRequest(commentsUrl);
1918

20-
final response = await _client.get(commentsUrl);
19+
final response = await _client.get(Uri.parse(commentsUrl));
2120
final json = jsonDecode(response.body);
2221

2322
yield serializers.deserialize(json, specifiedType: commentsBuiltList)
2423
as BuiltList<Comment>;
2524
}
2625

27-
Stream<Comment> getCommentBy({@required int id}) async* {
28-
if (id == null) {
29-
throw ArgumentError.notNull('id');
30-
}
26+
Stream<Comment> getCommentBy({required int id}) async* {
3127
_logRequest('$commentsUrl/$id');
3228

33-
final response = await _client.get('$commentsUrl/$id');
29+
final response = await _client.get(Uri.parse('$commentsUrl/$id'));
3430
final json = jsonDecode(response.body);
3531

3632
yield Comment.fromJson(json);

example/lib/data/comment.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ abstract class Comment implements Built<Comment, CommentBuilder> {
2323
static Serializer<Comment> get serializer => _$commentSerializer;
2424

2525
factory Comment.fromJson(Map<String, dynamic> json) =>
26-
serializers.deserializeWith<Comment>(serializer, json);
26+
serializers.deserializeWith<Comment>(serializer, json)!;
2727

28-
Map<String, dynamic> toJson() => serializers.serializeWith(serializer, this);
28+
Map<String, dynamic> toJson() =>
29+
serializers.serializeWith(serializer, this)! as Map<String, dynamic>;
2930
}

example/lib/data/comment.g.dart

Lines changed: 50 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/data/serializers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const commentsBuiltList = FullType(
1212
);
1313

1414
@SerializersFor([Comment])
15-
final Serializers _serializers = _$serializers;
15+
final Serializers _serializers = _$_serializers;
1616
final Serializers serializers = (_serializers.toBuilder()
1717
..addBuilderFactory(
1818
commentsBuiltList,

example/lib/data/serializers.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/detail_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'home_page.dart' show SnackBarExt;
99
class DetailPage extends StatelessWidget {
1010
final Comment comment;
1111

12-
const DetailPage({Key key, @required this.comment}) : super(key: key);
12+
const DetailPage({Key? key, required this.comment}) : super(key: key);
1313

1414
@override
1515
Widget build(BuildContext context) {
@@ -41,7 +41,7 @@ class DetailPage extends StatelessWidget {
4141
);
4242
},
4343
builder: (context, state, bloc) {
44-
final comment = state.content;
44+
final comment = state.content!;
4545

4646
return RefreshIndicator(
4747
onRefresh: bloc.refresh,

example/lib/home_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'detail_page.dart';
1111
// ignore_for_file: deprecated_member_use
1212

1313
class HomePage extends StatelessWidget {
14-
const HomePage({Key key}) : super(key: key);
14+
const HomePage({Key? key}) : super(key: key);
1515

1616
@override
1717
Widget build(BuildContext context) {
@@ -55,7 +55,7 @@ class HomePage extends StatelessWidget {
5555
child: CircularProgressIndicator(),
5656
);
5757
}
58-
final items = state.content;
58+
final items = state.content!;
5959

6060
return RefreshIndicator(
6161
child: ListView.separated(

example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import 'home_page.dart';
88
void main() {
99
final api = Api(http.Client());
1010
runApp(
11-
Provider<Api>(
11+
Provider<Api>.value(
12+
api,
1213
child: MyApp(),
13-
value: api,
1414
),
1515
);
1616
}

0 commit comments

Comments
 (0)