diff --git a/lib/apis/githost.dart b/lib/apis/githost.dart index 8f3639c8..345ef91d 100644 --- a/lib/apis/githost.dart +++ b/lib/apis/githost.dart @@ -1,18 +1,14 @@ -// @dart=2.9 - import 'dart:async'; -import 'package:flutter/foundation.dart'; - import 'package:collection/collection.dart'; -typedef OAuthCallback = void Function(GitHostException); +typedef OAuthCallback = void Function(GitHostException?); abstract class GitHost { void init(OAuthCallback oAuthCallback); Future launchOAuthScreen(); - Future getUserInfo(); + Future getUserInfo(); Future> listRepos(); Future createRepo(String name); Future getRepo(String name); @@ -25,9 +21,9 @@ class UserInfo { final String username; UserInfo({ - @required this.name, - @required this.email, - @required this.username, + required this.name, + required this.email, + required this.username, }); } @@ -38,31 +34,31 @@ class GitHostRepo { final String description; final String cloneUrl; - final DateTime updatedAt; + final DateTime? updatedAt; - final bool private; - final int stars; - final int forks; - final String language; - final int issues; - final String license; + final bool? private; + final int? stars; + final int? forks; + final String? language; + final int? issues; + final String? license; final List tags; GitHostRepo({ - @required this.name, - @required this.username, - @required this.fullName, - @required this.description, - @required this.cloneUrl, - @required this.updatedAt, - @required this.private, - @required this.stars, - @required this.forks, - @required this.language, - @required this.issues, - @required this.tags, - @required this.license, + required this.name, + required this.username, + required this.fullName, + required this.description, + required this.cloneUrl, + required this.updatedAt, + required this.private, + required this.stars, + required this.forks, + required this.language, + required this.issues, + required this.tags, + required this.license, }); Map toJson() => { @@ -94,7 +90,7 @@ class GitHostRepo { int get hashCode => toJson().hashCode; } -var _mapEquals = (const MapEquality()).equals; +final _mapEquals = (const MapEquality()).equals; class GitHostException implements Exception { static const OAuthFailed = GitHostException("OAuthFailed"); diff --git a/lib/apis/githost_factory.dart b/lib/apis/githost_factory.dart index 8dc3f9b8..f421e9f6 100644 --- a/lib/apis/githost_factory.dart +++ b/lib/apis/githost_factory.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'githost.dart'; import 'github.dart'; import 'gitlab.dart'; @@ -13,7 +11,7 @@ enum GitHostType { Custom, } -GitHost createGitHost(GitHostType type) { +GitHost? createGitHost(GitHostType type) { switch (type) { case GitHostType.GitHub: return GitHub(); diff --git a/lib/apis/github.dart b/lib/apis/github.dart index 27db0589..1535ba8d 100644 --- a/lib/apis/github.dart +++ b/lib/apis/github.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -104,7 +102,7 @@ class GitHub implements GitHost { response.statusCode.toString() + ": " + response.body); - return null; + return []; } List list = jsonDecode(response.body); @@ -164,7 +162,7 @@ class GitHub implements GitHost { throw GitHostException.MissingAccessCode; } - var userInfo = await getUserInfo(); + var userInfo = await (getUserInfo() as FutureOr); var owner = userInfo.username; var url = Uri.parse("https://api.github.com/repos/$owner/$name"); @@ -222,11 +220,11 @@ class GitHub implements GitHost { @visibleForTesting GitHostRepo repoFromJson(Map parsedJson) { - DateTime updatedAt; + DateTime? updatedAt; try { updatedAt = DateTime.parse(parsedJson['updated_at'].toString()); - } catch (e) { - Log.e(e); + } catch (e, st) { + Log.e("github repoFromJson", ex: e, stacktrace: st); } var licenseMap = parsedJson['license']; var fullName = parsedJson['full_name'].toString(); @@ -263,7 +261,7 @@ class GitHub implements GitHost { } @override - Future getUserInfo() async { + Future getUserInfo() async { if (_accessCode.isEmpty) { throw GitHostException.MissingAccessCode; } @@ -283,7 +281,7 @@ class GitHub implements GitHost { return null; } - Map map = jsonDecode(response.body); + Map? map = jsonDecode(response.body); if (map == null || map.isEmpty) { Log.d("Github getUserInfo: jsonDecode Failed " + response.statusCode.toString() + diff --git a/lib/apis/gitlab.dart b/lib/apis/gitlab.dart index 74e58f31..ef8b5022 100644 --- a/lib/apis/gitlab.dart +++ b/lib/apis/gitlab.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -21,7 +19,7 @@ class GitLab implements GitHost { "faf33c3716faf05bfb701b1b31e36c83a23c3ec2d7161f4ff00fba2275524d09"; var _platform = const MethodChannel('gitjournal.io/git'); - var _accessCode = ""; + String? _accessCode = ""; var _stateOAuth = ""; @override @@ -43,7 +41,7 @@ class GitLab implements GitHost { if (state != _stateOAuth) { Log.d("GitLab: OAuth State incorrect"); Log.d("Required State: " + _stateOAuth); - Log.d("Actual State: " + state); + Log.d("Actual State: " + state!); callback(GitHostException.OAuthFailed); return; } @@ -72,7 +70,7 @@ class GitLab implements GitHost { @override Future> listRepos() async { - if (_accessCode.isEmpty) { + if (_accessCode!.isEmpty) { throw GitHostException.MissingAccessCode; } @@ -90,7 +88,7 @@ class GitLab implements GitHost { response.statusCode.toString() + ": " + response.body); - return null; + return []; } List list = jsonDecode(response.body); @@ -107,7 +105,7 @@ class GitLab implements GitHost { @override Future createRepo(String name) async { - if (_accessCode.isEmpty) { + if (_accessCode!.isEmpty) { throw GitHostException.MissingAccessCode; } @@ -146,11 +144,11 @@ class GitLab implements GitHost { @override Future getRepo(String name) async { - if (_accessCode.isEmpty) { + if (_accessCode!.isEmpty) { throw GitHostException.MissingAccessCode; } - var userInfo = await getUserInfo(); + var userInfo = await (getUserInfo() as FutureOr); var repo = userInfo.username + '%2F' + name; var url = Uri.parse( "https://gitlab.com/api/v4/projects/$repo?access_token=$_accessCode"); @@ -172,7 +170,7 @@ class GitLab implements GitHost { @override Future addDeployKey(String sshPublicKey, String repo) async { - if (_accessCode.isEmpty) { + if (_accessCode!.isEmpty) { throw GitHostException.MissingAccessCode; } @@ -206,11 +204,11 @@ class GitLab implements GitHost { @visibleForTesting GitHostRepo repoFromJson(Map parsedJson) { - DateTime updatedAt; + DateTime? updatedAt; try { updatedAt = DateTime.parse(parsedJson['last_activity_at'].toString()); - } catch (e) { - Log.e(e); + } catch (e, st) { + Log.e("gitlab repoFromJson", ex: e, stacktrace: st); } var licenseMap = parsedJson['license']; @@ -247,8 +245,8 @@ class GitLab implements GitHost { } @override - Future getUserInfo() async { - if (_accessCode.isEmpty) { + Future getUserInfo() async { + if (_accessCode!.isEmpty) { throw GitHostException.MissingAccessCode; } @@ -264,7 +262,7 @@ class GitLab implements GitHost { return null; } - Map map = jsonDecode(response.body); + Map? map = jsonDecode(response.body); if (map == null || map.isEmpty) { Log.d("GitLab getUserInfo: jsonDecode Failed " + response.statusCode.toString() + diff --git a/lib/utils.dart b/lib/utils.dart index 9d625df0..465492b7 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'package:flutter/material.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -18,12 +16,10 @@ import 'utils/logger.dart'; Future getVersionString() async { var info = await PackageInfo.fromPlatform(); var versionText = ""; - if (info != null) { - versionText = info.appName + " " + info.version + "+" + info.buildNumber; + versionText = info.appName + " " + info.version + "+" + info.buildNumber; - if (JournalApp.isInDebugMode) { - versionText += " (Debug)"; - } + if (JournalApp.isInDebugMode) { + versionText += " (Debug)"; } return versionText; @@ -96,7 +92,7 @@ Future shareNote(Note note) async { return Share.share(note.serialize()); } -Future getTodayJournalEntry(NotesFolderFS rootFolder) async { +Future getTodayJournalEntry(NotesFolderFS rootFolder) async { var today = DateTime.now(); var matches = await rootFolder.matchNotes((n) async { var dt = n.created; diff --git a/test/apis/github_test.dart b/test/apis/github_test.dart index 300c68ab..a0231248 100644 --- a/test/apis/github_test.dart +++ b/test/apis/github_test.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:convert'; import 'dart:io'; diff --git a/test/apis/gitlab_test.dart b/test/apis/gitlab_test.dart index c293f59d..2e726895 100644 --- a/test/apis/gitlab_test.dart +++ b/test/apis/gitlab_test.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:convert'; import 'dart:io';