mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-17 18:49:55 +08:00
Always check if a Folder exists before accessing it
This kinds of bugs will be less frequent once we have non null by default enabled in Flutter. Fixes #164
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||
import 'package:gitjournal/screens/note_editor.dart';
|
||||
@ -50,14 +51,16 @@ NotesFolderFS getFolderForEditor(
|
||||
EditorType editorType,
|
||||
) {
|
||||
var spec = Settings.instance.defaultNewNoteFolderSpec;
|
||||
var journalSpec = Settings.instance.journalEditordefaultNewNoteFolderSpec;
|
||||
|
||||
switch (editorType) {
|
||||
case EditorType.Journal:
|
||||
return rootFolder.getFolderWithSpec(journalSpec);
|
||||
spec = Settings.instance.journalEditordefaultNewNoteFolderSpec;
|
||||
break;
|
||||
default:
|
||||
return rootFolder.getFolderWithSpec(spec);
|
||||
break;
|
||||
}
|
||||
|
||||
return rootFolder.getFolderWithSpec(spec) ?? rootFolder;
|
||||
}
|
||||
|
||||
Future<void> showAlertDialog(
|
||||
@ -68,3 +71,10 @@ Future<void> showAlertDialog(
|
||||
);
|
||||
return showDialog(context: context, builder: (context) => dialog);
|
||||
}
|
||||
|
||||
bool folderWithSpecExists(BuildContext context, String spec) {
|
||||
var stateContainer = Provider.of<StateContainer>(context, listen: false);
|
||||
var rootFolder = stateContainer.appState.notesFolder;
|
||||
|
||||
return rootFolder.getFolderWithSpec(spec) != null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user