Move all persistent state from AppState to Settings

This way all the persistant state of the app is managed from the same
place. It makes everything much easier. Also, it's required for when
GitJournal supports multiple repositories.
This commit is contained in:
Vishesh Handa
2020-09-24 23:44:32 +02:00
parent 1f32a3c10e
commit f30c52f595
11 changed files with 79 additions and 108 deletions

View File

@ -4,7 +4,6 @@ import 'package:flutter_driver/driver_extension.dart';
import 'package:path_provider/path_provider.dart';
import 'package:gitjournal/app.dart';
import 'package:gitjournal/appstate.dart';
import 'package:gitjournal/settings.dart';
import 'package:gitjournal/utils/datetime.dart';
@ -19,20 +18,20 @@ void main() async {
Settings.instance.load(pref);
await populateWithData(pref);
await JournalApp.main(pref);
await JournalApp.main();
}
// Generate lots of notes and folders better screenshots
Future<void> populateWithData(SharedPreferences pref) async {
var dir = await getApplicationDocumentsDirectory();
var appState = AppState(pref);
appState.gitBaseDirectory = dir.path;
appState.localGitRepoConfigured = true;
appState.localGitRepoFolderName = "journal_local";
appState.save(pref);
var settings = Settings.instance;
settings.gitBaseDirectory = dir.path;
settings.localGitRepoConfigured = true;
settings.localGitRepoFolderName = "journal_local";
settings.save();
var repoPath = p.join(dir.path, appState.localGitRepoFolderName);
var repoPath = p.join(dir.path, settings.localGitRepoFolderName);
await GitRepository.init(repoPath);
print("Filling fake data in $repoPath");