mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
Simplify the code
This commit is contained in:
10
lib/app.dart
10
lib/app.dart
@ -11,7 +11,6 @@ import 'package:easy_localization/easy_localization.dart';
|
|||||||
import 'package:easy_localization_loader/easy_localization_loader.dart';
|
import 'package:easy_localization_loader/easy_localization_loader.dart';
|
||||||
import 'package:flutter_sentry/flutter_sentry.dart';
|
import 'package:flutter_sentry/flutter_sentry.dart';
|
||||||
import 'package:package_info/package_info.dart';
|
import 'package:package_info/package_info.dart';
|
||||||
import 'package:path/path.dart' as p;
|
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:quick_actions/quick_actions.dart';
|
import 'package:quick_actions/quick_actions.dart';
|
||||||
@ -85,18 +84,13 @@ class JournalApp extends StatefulWidget {
|
|||||||
appState.remoteGitRepoConfigured = remotes.isNotEmpty;
|
appState.remoteGitRepoConfigured = remotes.isNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
final cacheDir = await getApplicationSupportDirectory();
|
appState.cacheDir = (await getApplicationSupportDirectory()).path;
|
||||||
|
|
||||||
Widget app = ChangeNotifierProvider.value(
|
Widget app = ChangeNotifierProvider.value(
|
||||||
value: settings,
|
value: settings,
|
||||||
child: ChangeNotifierProvider(
|
child: ChangeNotifierProvider(
|
||||||
create: (_) {
|
create: (_) {
|
||||||
return StateContainer(
|
return StateContainer(appState: appState, settings: settings);
|
||||||
appState: appState,
|
|
||||||
settings: settings,
|
|
||||||
gitBaseDirectory: appState.gitBaseDirectory,
|
|
||||||
cacheDirectory: cacheDir.path,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
child: ChangeNotifierProvider(
|
child: ChangeNotifierProvider(
|
||||||
child: JournalApp(appState),
|
child: JournalApp(appState),
|
||||||
|
@ -17,7 +17,9 @@ class AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NotesFolderFS notesFolder;
|
NotesFolderFS notesFolder;
|
||||||
|
|
||||||
var gitBaseDirectory = "";
|
var gitBaseDirectory = "";
|
||||||
|
var cacheDir = "";
|
||||||
|
|
||||||
bool remoteGitRepoConfigured = false;
|
bool remoteGitRepoConfigured = false;
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,6 @@ import 'package:gitjournal/utils/logger.dart';
|
|||||||
class StateContainer with ChangeNotifier {
|
class StateContainer with ChangeNotifier {
|
||||||
final AppState appState;
|
final AppState appState;
|
||||||
final Settings settings;
|
final Settings settings;
|
||||||
final String gitBaseDirectory;
|
|
||||||
final String cacheDirectory;
|
|
||||||
|
|
||||||
final _opLock = Lock();
|
final _opLock = Lock();
|
||||||
final _loadLock = Lock();
|
final _loadLock = Lock();
|
||||||
@ -37,12 +35,7 @@ class StateContainer with ChangeNotifier {
|
|||||||
|
|
||||||
String repoPath;
|
String repoPath;
|
||||||
|
|
||||||
StateContainer({
|
StateContainer({@required this.appState, @required this.settings}) {
|
||||||
@required this.appState,
|
|
||||||
@required this.settings,
|
|
||||||
@required this.gitBaseDirectory,
|
|
||||||
@required this.cacheDirectory,
|
|
||||||
}) {
|
|
||||||
repoPath = settings.buildRepoPath(appState.gitBaseDirectory);
|
repoPath = settings.buildRepoPath(appState.gitBaseDirectory);
|
||||||
|
|
||||||
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
||||||
@ -54,7 +47,7 @@ class StateContainer with ChangeNotifier {
|
|||||||
value: appState.remoteGitRepoConfigured.toString(),
|
value: appState.remoteGitRepoConfigured.toString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
var cachePath = p.join(cacheDirectory, "cache.json");
|
var cachePath = p.join(appState.cacheDir, "cache.json");
|
||||||
_notesCache = NotesCache(
|
_notesCache = NotesCache(
|
||||||
filePath: cachePath,
|
filePath: cachePath,
|
||||||
notesBasePath: _gitRepo.gitDirPath,
|
notesBasePath: _gitRepo.gitDirPath,
|
||||||
|
Reference in New Issue
Block a user