Skip to content

Commit 84af69d

Browse files
committed
move to null-safety
1 parent aaf3fe5 commit 84af69d

File tree

74 files changed

+589
-587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+589
-587
lines changed

lib/app_error.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ enum ErrorType {
33
BadResponse,
44
ServerError,
55
NotFound,
6-
NotCached
6+
NotCached,
77
}
88

99
class AppError {
1010
final ErrorType errCode;
11-
final String message;
11+
final String? message;
1212

1313
const AppError({
14-
this.errCode,
14+
required this.errCode,
1515
this.message,
1616
});
1717

1818
@override
1919
String toString() {
20-
if (message == null || message.isEmpty) {
20+
if (message == null || message!.isEmpty) {
2121
return errCode.toString();
2222
}
2323
return "$errCode: $message";
2424
}
25-
}
25+
}

lib/habr/api.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Habr {
3333

3434
Future<Either<AppError, PostPreviews>> findPosts(String query,
3535
{int page = 1, Order order = Order.Relevance}) async {
36-
String ordString = orderToText[order];
36+
String ordString = orderToText[order]!;
3737
final url =
3838
"$api_url_v2/articles/?query=$query&order=$ordString&fl=ru&hl=ru&page=$page";
3939
final response = await safe(http.get(Uri.parse(url)));

lib/habr/json_parsing.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:habr_app/models/author_info.dart';
22
import 'package:habr_app/models/models.dart';
33
import 'package:html/parser.dart' show parseFragment;
44

5-
AuthorAvatarInfo prepareAvatarUrl(String url) {
5+
AuthorAvatarInfo prepareAvatarUrl(String? url) {
66
if (url == null) return AuthorAvatarInfo(url: null);
77
if (url.startsWith("//")) url = url.replaceFirst("//", "https://");
88
return AuthorAvatarInfo(url: url);
@@ -70,11 +70,11 @@ PostPreviews parsePostPreviewsFromJson(Map<String, dynamic> data) {
7070
corporative: article['isCorporative'],
7171
title: _prepareHtmlString(article['titleHtml']),
7272
hubs: article['hubs']
73-
.map<String>((flow) => flow['title'] as String)
73+
.map<String>((flow) => flow['title'] as String?)
7474
.toList(),
7575
htmlPreview: "<div>${article['leadData']['textHtml']}</div>",
7676
flows: article['flows']
77-
.map<String>((flow) => flow['title'] as String)
77+
.map<String>((flow) => flow['title'] as String?)
7878
.toList(),
7979
publishDate: DateTime.parse(article['timePublished']),
8080
author: parseAuthorFromJson(article['author']),
@@ -99,5 +99,5 @@ AuthorInfo parseAuthorInfoFromJson(Map<String, dynamic> data) {
9999
}
100100

101101
String _prepareHtmlString(String str) {
102-
return parseFragment(str).text.trim();
102+
return parseFragment(str).text?.trim() ?? '';
103103
}

lib/models/author.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import 'author_avatar_info.dart';
33
class Author {
44
final String id;
55
final String alias;
6-
final String fullName;
7-
final String speciality;
6+
final String? fullName;
7+
final String? speciality;
88
final AuthorAvatarInfo avatar;
99

1010
const Author({
11-
this.id,
12-
this.alias,
13-
this.avatar,
11+
required this.id,
12+
required this.alias,
13+
required this.avatar,
1414
this.speciality,
1515
this.fullName,
1616
});

lib/models/author_avatar_info.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class AuthorAvatarInfo {
2-
final String url;
2+
final String? url;
33
final bool cached;
44
const AuthorAvatarInfo({this.url, this.cached = false});
55

6-
bool get isDefault => url == null || url.isEmpty;
6+
bool get isDefault => url == null || url!.isEmpty;
77
bool get isNotDefault => !isDefault;
88
}

lib/models/author_info.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ import 'package:habr_app/models/author_avatar_info.dart';
33

44
class AuthorInfo {
55
final String alias;
6-
final String fullName;
7-
final String speciality;
8-
final String about;
9-
final AuthorAvatarInfo avatar;
6+
final String? fullName;
7+
final String? speciality;
8+
final String? about;
9+
final AuthorAvatarInfo? avatar;
1010

1111
final int postCount;
12-
final int followCount;
13-
final int folowersCount;
12+
final int? followCount;
13+
final int? folowersCount;
1414

1515
final DateTime lastActivityTime;
1616
final DateTime registerTime;
1717

18-
final int rating;
18+
final int? rating;
1919

20-
final num karma;
20+
final num? karma;
2121

2222
const AuthorInfo({
23-
this.alias,
23+
required this.alias,
2424
this.fullName,
2525
this.speciality,
2626
this.about,
2727
this.avatar,
28-
this.postCount,
28+
required this.postCount,
2929
this.followCount,
3030
this.folowersCount,
31-
this.lastActivityTime,
32-
this.registerTime,
31+
required this.lastActivityTime,
32+
required this.registerTime,
3333
this.rating,
3434
this.karma,
3535
});

lib/models/cached_image_info.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class CachedImageInfo {
2-
CachedImageInfo({this.url, this.path});
2+
CachedImageInfo({required this.url, required this.path});
33

44
String url;
55
String path;

lib/models/cached_post.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ class CachedPost {
88
final DateTime insertDate;
99
final String authorId;
1010

11-
const CachedPost(
12-
{this.id,
13-
this.title,
14-
this.body,
15-
this.publishDate,
16-
this.authorId,
17-
this.insertDate});
11+
const CachedPost({
12+
required this.id,
13+
required this.title,
14+
required this.body,
15+
required this.publishDate,
16+
required this.authorId,
17+
required this.insertDate,
18+
});
1819

1920
CachedPost.fromPost(
2021
Post post, {
21-
this.insertDate,
22+
required this.insertDate,
2223
}) : id = post.id,
2324
title = post.title,
2425
body = post.body,

lib/models/comment.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@ import 'author.dart';
22

33
class Comment {
44
final int id;
5-
final int parentId;
6-
final int level;
5+
final int? parentId;
6+
final int? level;
77
final bool banned;
8-
final DateTime timePublished;
9-
final DateTime timeChanged;
10-
final List<int> children;
11-
final Author author;
12-
final String message;
8+
final DateTime? timePublished;
9+
final DateTime? timeChanged;
10+
final List<int>? children;
11+
final Author? author;
12+
final String? message;
1313

14-
bool get notBanned => !banned;
14+
bool get notBanned => banned;
1515

1616
Comment({
17-
this.id,
17+
required this.id,
1818
this.parentId,
1919
this.level,
2020
this.timePublished,
2121
this.timeChanged,
2222
this.children,
2323
this.author,
2424
this.message,
25-
this.banned,
25+
required this.banned,
2626
});
2727

2828
Comment copyWith({
29-
int id,
30-
int parentId,
31-
int level,
32-
bool banned,
33-
DateTime timePublished,
34-
DateTime timeChanged,
35-
List<int> children,
36-
Author author,
37-
String message,
29+
int? id,
30+
int? parentId,
31+
int? level,
32+
bool? banned,
33+
DateTime? timePublished,
34+
DateTime? timeChanged,
35+
List<int>? children,
36+
Author? author,
37+
String? message,
3838
}) {
3939
return Comment(
4040
id: id ?? this.id,
@@ -55,7 +55,7 @@ class Comments {
5555
final List<int> threads;
5656

5757
Comments({
58-
this.comments,
59-
this.threads,
58+
required this.comments,
59+
required this.threads,
6060
});
6161
}

lib/models/post.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ class Post implements PostInfo {
1515
final DateTime publishDate;
1616
final Author author;
1717

18-
const Post({this.id, this.title, this.body, this.publishDate, this.author});
18+
const Post({
19+
required this.id,
20+
required this.title,
21+
required this.body,
22+
required this.publishDate,
23+
required this.author,
24+
});
1925
}
2026

2127
class ParsedPost implements PostInfo {
@@ -26,10 +32,10 @@ class ParsedPost implements PostInfo {
2632
final Author author;
2733

2834
const ParsedPost({
29-
this.id,
30-
this.title,
31-
this.parsedBody,
32-
this.publishDate,
33-
this.author,
35+
required this.id,
36+
required this.title,
37+
required this.parsedBody,
38+
required this.publishDate,
39+
required this.author,
3440
});
3541
}

0 commit comments

Comments
 (0)