Skip to content

Commit 73f62a6

Browse files
authored
Merge pull request #249 from SpinlockLabs/nullsafe_2
Nullsafe 2
2 parents 77e02f3 + 1eee871 commit 73f62a6

38 files changed

+328
-398
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
- For web: browser specific helper methods have moved. use import `package:github/browser_helper.dart` (renderMarkdown, and createAvatorImage)
7373
- `createGithubClient(...)` has been removed. Just create a GitHub object directly now.
7474
- `findAuthenticationFromEnvironment` now works in both server/flutter and web environments
75-
- On the web, it will check the query string first, then localstorage
75+
- On the web, it will check the query string first, then session storage
7676
- all static methods are now factory constructors
7777
- fromJSON is now fromJson everywhere
7878
- toJSON is now toJson everywhere

build.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
targets:
2+
$default:
3+
builders:
4+
json_serializable:
5+
options:
6+
# Options configure how source code is generated for every
7+
# `@JsonSerializable`-annotated class in the package.
8+
field_rename: snake

example/languages.dart

+2-11
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,9 @@ Future<void> main() async {
1414
}
1515

1616
Future<void> loadRepository() async {
17-
String? user = 'dart-lang';
18-
String? reponame = 'sdk';
19-
2017
final params = queryString;
21-
22-
if (params.containsKey('user')) {
23-
user = params['user'];
24-
}
25-
26-
if (params.containsKey('repo')) {
27-
reponame = params['repo'];
28-
}
18+
var user = params['user'] ?? 'dart-lang';
19+
var reponame = params['repo'] ?? 'sdk';
2920

3021
document.getElementById('name')!.setInnerHtml('$user/$reponame');
3122

example/repos.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ List<Repository>? repos;
1010

1111
Map<String, Comparator<Repository>> sorts = {
1212
'stars': (Repository a, Repository b) =>
13-
b.stargazersCount!.compareTo(a.stargazersCount!),
13+
b.stargazersCount.compareTo(a.stargazersCount),
1414
'forks': (Repository a, Repository b) =>
15-
b.forksCount!.compareTo(a.forksCount!),
15+
b.forksCount.compareTo(a.forksCount),
1616
'created': (Repository a, Repository b) =>
1717
b.createdAt!.compareTo(a.createdAt!),
1818
'pushed': (Repository a, Repository b) => b.pushedAt!.compareTo(a.pushedAt!),
19-
'size': (Repository a, Repository b) => b.size!.compareTo(a.size!)
19+
'size': (Repository a, Repository b) => b.size.compareTo(a.size)
2020
};
2121

2222
Future<void> main() async {
@@ -53,8 +53,8 @@ void updateRepos(
5353
<div class="repo" id="repo_${repo.name}">
5454
<div class="line"></div>
5555
<h2><a href="${repo.htmlUrl}">${repo.name}</a></h2>
56-
${repo.description != "" && repo.description != null ? "<b>Description</b>: ${repo.description}<br/>" : ""}
57-
<b>Language</b>: ${repo.language ?? "Unknown"}
56+
${repo.description != "" ? "<b>Description</b>: ${repo.description}<br/>" : ""}
57+
<b>Language</b>: ${repo.language}
5858
<br/>
5959
<b>Default Branch</b>: ${repo.defaultBranch}
6060
<br/>
@@ -92,7 +92,7 @@ void loadRepos([int Function(Repository a, Repository b)? compare]) {
9292
}
9393
}
9494

95-
compare ??= (a, b) => a.name!.compareTo(b.name!);
95+
compare ??= (a, b) => a.name.compareTo(b.name);
9696

9797
github.repositories.listUserRepositories(user!).toList().then((repos) {
9898
_reposCache = repos;

example/stars.dart

+2-10
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,8 @@ Future<void> main() async {
1212
}
1313

1414
void loadStars() {
15-
String? user = 'SpinlockLabs';
16-
String? repo = 'github.dart';
17-
18-
if (queryString.containsKey('user')) {
19-
user = queryString['user'];
20-
}
21-
22-
if (queryString.containsKey('repo')) {
23-
repo = queryString['repo'];
24-
}
15+
var user = queryString['user'] ?? 'SpinlockLabs';
16+
var repo = queryString['repo'] ?? 'github.dart';
2517

2618
querySelector('#title')!.appendText(' for $user/$repo');
2719

example/status.dart

-17
This file was deleted.

example/status.html

-22
This file was deleted.

lib/src/common/model/authorizations.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:json_annotation/json_annotation.dart';
55
part 'authorizations.g.dart';
66

77
/// Model class for an authorization.
8-
@JsonSerializable(fieldRename: FieldRename.snake)
8+
@JsonSerializable()
99
class Authorization {
1010
Authorization(
1111
{this.id,
@@ -34,7 +34,7 @@ class Authorization {
3434
}
3535

3636
/// Model class for an application of an [Authorization].
37-
@JsonSerializable(fieldRename: FieldRename.snake)
37+
@JsonSerializable()
3838
class AuthorizationApplication {
3939
AuthorizationApplication({this.url, this.name, this.clientId});
4040

@@ -47,7 +47,7 @@ class AuthorizationApplication {
4747
Map<String, dynamic> toJson() => _$AuthorizationApplicationToJson(this);
4848
}
4949

50-
@JsonSerializable(fieldRename: FieldRename.snake)
50+
@JsonSerializable()
5151
class CreateAuthorization {
5252
CreateAuthorization(this.note,
5353
{this.scopes, this.noteUrl, this.clientId, this.clientSecret});

lib/src/common/model/gists.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class GistHistoryEntry {
124124
}
125125

126126
/// Model class for gist comments.
127-
@JsonSerializable(fieldRename: FieldRename.snake)
127+
@JsonSerializable()
128128
class GistComment {
129129
GistComment({
130130
this.id,
@@ -146,7 +146,7 @@ class GistComment {
146146
}
147147

148148
/// Model class for a new gist comment to be created.
149-
@JsonSerializable(fieldRename: FieldRename.snake)
149+
@JsonSerializable()
150150
class CreateGistComment {
151151
CreateGistComment(this.body);
152152
String? body;

lib/src/common/model/git.dart

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:json_annotation/json_annotation.dart';
55
part 'git.g.dart';
66

77
/// Model class for a blob.
8-
@JsonSerializable(fieldRename: FieldRename.snake)
8+
@JsonSerializable()
99
class GitBlob {
1010
GitBlob({
1111
this.content,
@@ -28,7 +28,7 @@ class GitBlob {
2828
/// Model class for a new blob to be created.
2929
///
3030
/// The [encoding] can be either 'utf-8' or 'base64'.
31-
@JsonSerializable(fieldRename: FieldRename.snake)
31+
@JsonSerializable()
3232
class CreateGitBlob {
3333
CreateGitBlob(this.content, this.encoding);
3434

@@ -44,7 +44,7 @@ class CreateGitBlob {
4444
///
4545
/// Note: This is the raw [GitCommit]. The [RepositoryCommit] is a repository
4646
/// commit containing GitHub-specific information.
47-
@JsonSerializable(fieldRename: FieldRename.snake)
47+
@JsonSerializable()
4848
class GitCommit {
4949
GitCommit({
5050
this.sha,
@@ -73,7 +73,7 @@ class GitCommit {
7373
}
7474

7575
/// Model class for a new commit to be created.
76-
@JsonSerializable(fieldRename: FieldRename.snake)
76+
@JsonSerializable()
7777
class CreateGitCommit {
7878
CreateGitCommit(this.message, this.tree,
7979
{this.parents, this.committer, this.author});
@@ -117,7 +117,7 @@ class GitCommitUser {
117117
}
118118

119119
/// Model class for a GitHub tree.
120-
@JsonSerializable(fieldRename: FieldRename.snake)
120+
@JsonSerializable()
121121
class GitTree {
122122
String? sha;
123123
String? url;
@@ -139,7 +139,7 @@ class GitTree {
139139
/// Model class for the contents of a tree structure. [GitTreeEntry] can
140140
/// represent either a blog, a commit (in the case of a submodule), or another
141141
/// tree.
142-
@JsonSerializable(fieldRename: FieldRename.snake)
142+
@JsonSerializable()
143143
class GitTreeEntry {
144144
String? path;
145145
String? mode;
@@ -156,7 +156,7 @@ class GitTreeEntry {
156156
}
157157

158158
/// Model class for a new tree to be created.
159-
@JsonSerializable(fieldRename: FieldRename.snake)
159+
@JsonSerializable()
160160
class CreateGitTree {
161161
CreateGitTree(this.entries, {this.baseTree});
162162

@@ -176,7 +176,7 @@ class CreateGitTree {
176176
}
177177

178178
/// Model class for a new tree entry to be created.
179-
@JsonSerializable(fieldRename: FieldRename.snake)
179+
@JsonSerializable()
180180
class CreateGitTreeEntry {
181181
/// Constructor.
182182
/// Either [sha] or [content] must be defined.
@@ -199,7 +199,7 @@ class CreateGitTreeEntry {
199199
}
200200

201201
/// Model class for a reference.
202-
@JsonSerializable(fieldRename: FieldRename.snake)
202+
@JsonSerializable()
203203
class GitReference {
204204
GitReference({
205205
this.ref,
@@ -216,7 +216,7 @@ class GitReference {
216216
}
217217

218218
/// Model class for a tag.
219-
@JsonSerializable(fieldRename: FieldRename.snake)
219+
@JsonSerializable()
220220
class GitTag {
221221
GitTag({
222222
this.tag,
@@ -239,7 +239,7 @@ class GitTag {
239239
}
240240

241241
/// Model class for a new tag to be created.
242-
@JsonSerializable(fieldRename: FieldRename.snake)
242+
@JsonSerializable()
243243
class CreateGitTag {
244244
CreateGitTag(this.tag, this.message, this.object, this.type, this.tagger);
245245

@@ -255,7 +255,7 @@ class CreateGitTag {
255255
}
256256

257257
/// Model class for an object referenced by [GitReference] and [GitTag].
258-
@JsonSerializable(fieldRename: FieldRename.snake)
258+
@JsonSerializable()
259259
class GitObject {
260260
GitObject(this.type, this.sha, this.url);
261261
String? type;

0 commit comments

Comments
 (0)