Skip to content

Commit

Permalink
feat: impl stateful module route
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Nov 9, 2024
1 parent 7d8a254 commit 9d25dee
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 101 deletions.
36 changes: 22 additions & 14 deletions lib/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,54 @@ import 'view/universal/universal.dart';

const clientSourceCodeUrl = 'github.com/tuihub/waiter';

class App {
class Module {
final ModuleName name;
IconData Function(BuildContext context) icon;
void Function(BuildContext context) go;

App(this.name, this.icon, this.go);
Module(this.name, this.icon, this.go);
}

final moduleList = [
// App('Home', Icons.home, const HomePage()),
App(ModuleName.tiphereth, (context) {
final modules = [
Module(ModuleName.tiphereth, (context) {
return UniversalUI.of(context).icons.tiphereth;
}, (context) {
const TipherethRootRoute().go(context);
}),
App(ModuleName.gebura, (context) {
Module(ModuleName.yesod, (context) {
return UniversalUI.of(context).icons.yesod;
}, (context) {
const YesodRootRoute().go(context);
}),
Module(ModuleName.gebura, (context) {
return UniversalUI.of(context).icons.gebura;
}, (context) {
const GeburaRootRoute().go(context);
}),
App(ModuleName.yesod, (context) {
return UniversalUI.of(context).icons.yesod;
Module(ModuleName.chesed, (context) {
return UniversalUI.of(context).icons.chesed;
}, (context) {
const YesodRootRoute().go(context);
const ChesedRootRoute().go(context);
}),
// App(ModuleName.chesed, Icons.photo_album),
// App('Ffi', Icons.timelapse, const FfiTestPage()),
App(ModuleName.notification, (context) {
Module(ModuleName.notification, (context) {
return UniversalUI.of(context).icons.notification;
}, (context) {
const NotificationRootRoute().go(context);
}),
App(ModuleName.settings, (context) {
Module(ModuleName.settings, (context) {
return UniversalUI.of(context).icons.settings;
}, (context) {
const SettingsRootRoute().go(context);
}),
];

final moduleMap = Map.fromEntries(moduleList.map((e) => MapEntry(e.name, e)));
final moduleMap = Map.fromEntries(modules.map((e) => MapEntry(e.name, e)));

final offlineAllowedModules = [
ModuleName.tiphereth,
ModuleName.gebura,
ModuleName.settings,
];

const appDefaultAccentColor = Color.fromARGB(255, 255, 145, 0);
// const AppBackgroudColor = Color.fromARGB(255, 32, 34, 37);
Expand Down
33 changes: 1 addition & 32 deletions lib/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ import 'view/pages/yesod/manage_yesod_action_page.dart';
import 'view/pages/yesod/manage_yesod_feed_page.dart';
import 'view/pages/yesod/yesod_nav.dart';
import 'view/pages/yesod/yesod_recent_page.dart';
import 'view/universal/button.dart';
import 'view/universal/spacing.dart';

part 'route.g.dart';

Expand Down Expand Up @@ -146,27 +144,6 @@ final GlobalKey<NavigatorState> _settingsNavigateKey =
final mainWindowKey = GlobalKey();
final appFrameKey = GlobalKey();

class AppRoute extends GoRouteData {
const AppRoute();

@override
NoTransitionPage<void> buildPage(BuildContext context, GoRouterState state) {
return NoTransitionPage(
child: MainWindow(
child: Column(
children: SpacingHelper.listSpacing(height: 8, children: [
Text('Wrong route: ${state.matchedLocation}'),
UniversalElevatedButton(
onPressed: () => const InitRoute().go(context),
child: const Text('Back to initial page'),
),
]),
),
),
);
}
}

@TypedGoRoute<InitRoute>(path: '/init')
class InitRoute extends GoRouteData {
const InitRoute();
Expand Down Expand Up @@ -272,6 +249,7 @@ class ModuleRoute extends StatefulShellRouteData {
key: mainWindowKey,
child: AppFramePage(
key: appFrameKey,
navigationShell: navigationShell,
child: navigationShell,
),
);
Expand Down Expand Up @@ -301,7 +279,6 @@ class TipherethRootRoute extends GoRouteData {
context.read<TipherethBloc>().add(TipherethGetAccountsEvent());
return const NoTransitionPage(
child: ModuleFramePage(
selectedNav: ModuleName.tiphereth,
leftPart: TipherethFramePage(),
),
);
Expand Down Expand Up @@ -382,7 +359,6 @@ class YesodFunctionRoute extends GoRouteData {
}
return NoTransitionPage(
child: ModuleFramePage(
selectedNav: ModuleName.yesod,
leftPart: YesodNav(
function: function,
),
Expand Down Expand Up @@ -425,7 +401,6 @@ class GeburaStoreRoute extends GoRouteData {
return NoTransitionPage(
child: GeburaRoute.rootWidget(
child: const ModuleFramePage(
selectedNav: ModuleName.gebura,
leftPart: GeburaNav(
function: GeburaFunctions.store,
),
Expand All @@ -444,7 +419,6 @@ class GeburaLibraryRoute extends GoRouteData {
return NoTransitionPage(
child: GeburaRoute.rootWidget(
child: const ModuleFramePage(
selectedNav: ModuleName.gebura,
leftPart: GeburaNav(
function: GeburaFunctions.library,
),
Expand Down Expand Up @@ -481,7 +455,6 @@ class GeburaLibrarySettingsRoute extends GoRouteData {
return NoTransitionPage(
child: GeburaRoute.rootWidget(
child: ModuleFramePage(
selectedNav: ModuleName.gebura,
leftPart: const GeburaNav(
function: GeburaFunctions.librarySettings,
),
Expand Down Expand Up @@ -509,7 +482,6 @@ class GeburaLibraryDetailRoute extends GoRouteData {
return NoTransitionPage(
child: GeburaRoute.rootWidget(
child: ModuleFramePage(
selectedNav: ModuleName.gebura,
leftPart: GeburaNav(
function: GeburaFunctions.library,
selectedItem: uuid ?? '',
Expand All @@ -536,7 +508,6 @@ class ChesedRootRoute extends GoRouteData {
context.read<ChesedBloc>().add(ChesedSearchImagesEvent(''));
return const NoTransitionPage(
child: ModuleFramePage(
selectedNav: ModuleName.chesed,
leftPart: ChesedHome(),
),
);
Expand All @@ -558,7 +529,6 @@ class NotificationRootRoute extends GoRouteData {
context.read<NetzachBloc>().add(NetzachSystemNotificationLoadEvent(1));
return const NoTransitionPage(
child: ModuleFramePage(
selectedNav: ModuleName.notification,
leftPart: NotificationPage(),
),
);
Expand Down Expand Up @@ -642,7 +612,6 @@ class SettingsFunctionRoute extends GoRouteData {
}
return NoTransitionPage(
child: ModuleFramePage(
selectedNav: ModuleName.settings,
leftPart: SettingsNav(
function: function,
),
Expand Down
Loading

0 comments on commit 9d25dee

Please sign in to comment.