mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-25 16:19:58 +08:00
Use firstWhereOrNull
Simplifies the code
This commit is contained in:
@ -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<void> _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");
|
||||
|
@ -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<GitHostSetupRepoSelector> {
|
||||
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;
|
||||
|
@ -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<NoteBacklinkRenderer> {
|
||||
|
||||
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<NoteBacklinkRenderer> {
|
||||
|
||||
return matchedNote.filePath == widget.note.filePath;
|
||||
},
|
||||
orElse: () => null,
|
||||
);
|
||||
|
||||
// Log.d("NoteBacklinkRenderer Predicate ${matchedLink != null}");
|
||||
|
Reference in New Issue
Block a user