mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-24 19:24:45 +08:00
App: minor refactor
This allows me to reuse parts of the app global variable initialization in other parts of the code.
This commit is contained in:
74
lib/app.dart
74
lib/app.dart
@ -57,36 +57,14 @@ class JournalApp extends StatefulWidget {
|
|||||||
);
|
);
|
||||||
await repoManager.buildActiveRepository();
|
await repoManager.buildActiveRepository();
|
||||||
|
|
||||||
Widget app = ChangeNotifierProvider.value(
|
|
||||||
value: repoManager,
|
|
||||||
child: Consumer<RepositoryManager>(
|
|
||||||
builder: (_, repoManager, __) => ChangeNotifierProvider.value(
|
|
||||||
value: repoManager.currentRepo,
|
|
||||||
child: Consumer<GitJournalRepo>(
|
|
||||||
builder: (_, repo, __) => ChangeNotifierProvider<Settings>.value(
|
|
||||||
value: repo.settings,
|
|
||||||
child: Consumer<GitJournalRepo>(
|
|
||||||
builder: (_, repo, __) =>
|
|
||||||
ChangeNotifierProvider<NotesFolderFS>.value(
|
|
||||||
value: repo.notesFolder,
|
|
||||||
child: JournalApp(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
app = ChangeNotifierProvider.value(
|
|
||||||
value: appSettings,
|
|
||||||
child: app,
|
|
||||||
);
|
|
||||||
|
|
||||||
InAppPurchases.confirmProPurchaseBoot();
|
InAppPurchases.confirmProPurchaseBoot();
|
||||||
|
|
||||||
runApp(EasyLocalization(
|
runApp(EasyLocalization(
|
||||||
child: app,
|
child: GitJournalChangeNotifiers(
|
||||||
|
repoManager: repoManager,
|
||||||
|
appSettings: appSettings,
|
||||||
|
child: JournalApp(),
|
||||||
|
),
|
||||||
supportedLocales: [
|
supportedLocales: [
|
||||||
const Locale('en', 'US'),
|
const Locale('en', 'US'),
|
||||||
], // Remember to update Info.plist
|
], // Remember to update Info.plist
|
||||||
@ -350,3 +328,45 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GitJournalChangeNotifiers extends StatelessWidget {
|
||||||
|
final RepositoryManager repoManager;
|
||||||
|
final AppSettings appSettings;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
GitJournalChangeNotifiers({
|
||||||
|
required this.repoManager,
|
||||||
|
required this.appSettings,
|
||||||
|
required this.child,
|
||||||
|
Key? key,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var app = ChangeNotifierProvider.value(
|
||||||
|
value: repoManager,
|
||||||
|
child: Consumer<RepositoryManager>(
|
||||||
|
builder: (_, repoManager, __) => ChangeNotifierProvider.value(
|
||||||
|
value: repoManager.currentRepo,
|
||||||
|
child: Consumer<GitJournalRepo>(
|
||||||
|
builder: (_, repo, __) => ChangeNotifierProvider<Settings>.value(
|
||||||
|
value: repo.settings,
|
||||||
|
child: Consumer<GitJournalRepo>(
|
||||||
|
builder: (_, repo, __) =>
|
||||||
|
ChangeNotifierProvider<NotesFolderFS>.value(
|
||||||
|
value: repo.notesFolder,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return ChangeNotifierProvider.value(
|
||||||
|
value: appSettings,
|
||||||
|
child: app,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user