diff --git a/lib/repository.dart b/lib/repository.dart index 0203991b..cfc67864 100644 --- a/lib/repository.dart +++ b/lib/repository.dart @@ -6,6 +6,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:collection/collection.dart'; import 'package:dart_git/config.dart'; import 'package:dart_git/dart_git.dart'; import 'package:git_bindings/git_bindings.dart'; @@ -544,8 +545,8 @@ class GitJournalRepo with ChangeNotifier { } var remoteConfig = repo.config.remotes.first; var remoteBranches = await repo.remoteBranches(remoteConfig.name); - var remoteBranchRef = remoteBranches - .firstWhere((ref) => ref.name.branchName() == name, orElse: null); + var remoteBranchRef = + remoteBranches.firstWhereOrNull((ref) => ref.name.branchName() == name); if (remoteBranchRef == null) { return ""; } @@ -579,9 +580,8 @@ Future _addFileInRepo({ }) async { var repoPath = repo.repoPath; var dirList = await Directory(repoPath).list().toList(); - var anyFileInRepo = dirList.firstWhere( + var anyFileInRepo = dirList.firstWhereOrNull( (fs) => fs.statSync().type == FileSystemEntityType.file, - orElse: () => null, ); if (anyFileInRepo == null) { Log.i("Adding .ignore file"); diff --git a/lib/setup/repo_selector.dart b/lib/setup/repo_selector.dart index 4e0a40a8..22c9bd2c 100644 --- a/lib/setup/repo_selector.dart +++ b/lib/setup/repo_selector.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; +import 'package:collection/collection.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:function_types/function_types.dart'; import 'package:intl/intl.dart'; @@ -101,10 +102,7 @@ class GitHostSetupRepoSelectorState extends State { fetchedRepos = true; }); - var repo = repos.firstWhere( - (r) => r.fullName.endsWith('/journal'), - orElse: () => null, - ); + var repo = repos.firstWhereOrNull((r) => r.fullName.endsWith('/journal')); if (repo != null) { setState(() { selectedRepo = repo; diff --git a/lib/widgets/notes_backlinks.dart b/lib/widgets/notes_backlinks.dart index c283bdc4..f09643b9 100644 --- a/lib/widgets/notes_backlinks.dart +++ b/lib/widgets/notes_backlinks.dart @@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:collection/collection.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:gitjournal/core/link.dart'; @@ -45,7 +46,7 @@ class _NoteBacklinkRendererState extends State { var links = await n.fetchLinks(); var linkResolver = LinkResolver(n); - var matchedLink = links.firstWhere( + var matchedLink = links.firstWhereOrNull( (l) { var matchedNote = linkResolver.resolveLink(l); if (matchedNote == null) { @@ -54,7 +55,6 @@ class _NoteBacklinkRendererState extends State { return matchedNote.filePath == widget.note.filePath; }, - orElse: () => null, ); // Log.d("NoteBacklinkRenderer Predicate ${matchedLink != null}");