mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-14 23:40:30 +08:00
Make Repository a consumer of RepoManager
I feel like I really don't understand Provider properly and this is going to blow up in my face.
This commit is contained in:
22
lib/app.dart
22
lib/app.dart
@ -19,6 +19,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import 'package:gitjournal/analytics.dart';
|
import 'package:gitjournal/analytics.dart';
|
||||||
import 'package:gitjournal/app_router.dart';
|
import 'package:gitjournal/app_router.dart';
|
||||||
import 'package:gitjournal/app_settings.dart';
|
import 'package:gitjournal/app_settings.dart';
|
||||||
|
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||||
import 'package:gitjournal/iap.dart';
|
import 'package:gitjournal/iap.dart';
|
||||||
import 'package:gitjournal/repository.dart';
|
import 'package:gitjournal/repository.dart';
|
||||||
import 'package:gitjournal/repository_manager.dart';
|
import 'package:gitjournal/repository_manager.dart';
|
||||||
@ -54,16 +55,21 @@ class JournalApp extends StatefulWidget {
|
|||||||
cacheDir: cacheDir,
|
cacheDir: cacheDir,
|
||||||
pref: pref,
|
pref: pref,
|
||||||
);
|
);
|
||||||
var repo = await repoManager.buildActiveRepository();
|
await repoManager.buildActiveRepository();
|
||||||
|
|
||||||
Widget app = ChangeNotifierProvider.value(
|
Widget app = ChangeNotifierProvider.value(
|
||||||
value: repo,
|
value: repoManager,
|
||||||
child: Consumer<Repository>(
|
child: Consumer<RepositoryManager>(
|
||||||
builder: (_, repo, __) => ChangeNotifierProvider.value(
|
builder: (_, repoManager, __) => ChangeNotifierProvider.value(
|
||||||
value: repo.settings,
|
value: repoManager.currentRepo,
|
||||||
child: ChangeNotifierProvider.value(
|
child: Consumer<Repository>(
|
||||||
child: JournalApp(),
|
builder: (_, repo, __) => ChangeNotifierProvider<Settings>.value(
|
||||||
value: repo.notesFolder,
|
value: repo.settings,
|
||||||
|
child: ChangeNotifierProvider<NotesFolderFS>.value(
|
||||||
|
child: JournalApp(),
|
||||||
|
value: repo.notesFolder,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -36,6 +36,8 @@ class RepositoryManager with ChangeNotifier {
|
|||||||
// From the pref load all the RepositoryInfos
|
// From the pref load all the RepositoryInfos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Repository get currentRepo => _repo;
|
||||||
|
|
||||||
Future<Repository> buildActiveRepository() async {
|
Future<Repository> buildActiveRepository() async {
|
||||||
if (_repo != null) {
|
if (_repo != null) {
|
||||||
return _repo;
|
return _repo;
|
||||||
@ -51,6 +53,8 @@ class RepositoryManager with ChangeNotifier {
|
|||||||
pref: pref,
|
pref: pref,
|
||||||
id: currentId,
|
id: currentId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
notifyListeners();
|
||||||
return _repo;
|
return _repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user