Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Router] made NeumorphicApp able to create from RouterDelegate #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 123 additions & 34 deletions lib/src/widget/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class NeumorphicApp extends StatelessWidget {
final Locale? locale;
final Widget? home;
final Iterable<Locale> supportedLocales;
final Map<String, WidgetBuilder> routes;
final Map<String, WidgetBuilder>? routes;
final RouteFactory? onGenerateRoute;
final RouteFactory? onUnknownRoute;
final GenerateAppTitle? onGenerateTitle;
final GlobalKey<NavigatorState>? navigatorKey;
final List<NavigatorObserver> navigatorObservers;
final List<NavigatorObserver>? navigatorObservers;
final InitialRouteListFactory? onGenerateInitialRoutes;
final bool debugShowCheckedModeBanner;
final Widget Function(BuildContext, Widget?)? builder;
Expand All @@ -34,8 +34,22 @@ class NeumorphicApp extends StatelessWidget {
final Map<LogicalKeySet, Intent>? shortcuts;
final Map<Type, Action<Intent>>? actions;

/// {@macro flutter.widgets.widgetsApp.routeInformationProvider}
final RouteInformationProvider? routeInformationProvider;

/// {@macro flutter.widgets.widgetsApp.routeInformationParser}
final RouteInformationParser<Object>? routeInformationParser;

/// {@macro flutter.widgets.widgetsApp.routerDelegate}
final RouterDelegate<Object>? routerDelegate;

/// {@macro flutter.widgets.widgetsApp.backButtonDispatcher}
final BackButtonDispatcher? backButtonDispatcher;

final bool debugShowMaterialGrid;

bool get _usesRouter => routerDelegate != null;

const NeumorphicApp({
Key? key,
this.title = '',
Expand Down Expand Up @@ -70,7 +84,51 @@ class NeumorphicApp extends StatelessWidget {
this.debugShowMaterialGrid = false,
this.shortcuts,
this.actions,
}) : super(key: key);
}) : routeInformationProvider = null,
routeInformationParser = null,
routerDelegate = null,
backButtonDispatcher = null,
super(key: key);

const NeumorphicApp.router({
Key? key,
required RouterDelegate<Object> this.routerDelegate,
required RouteInformationParser<Object> this.routeInformationParser,
this.routeInformationProvider,
this.backButtonDispatcher,
this.title = '',
this.color,
this.debugShowCheckedModeBanner = true,
this.onGenerateTitle,
this.theme = neumorphicDefaultTheme,
this.darkTheme = neumorphicDefaultDarkTheme,
this.locale,
this.localizationsDelegates,
this.supportedLocales = const <Locale>[Locale('en', 'US')],
this.themeMode = ThemeMode.system,
this.materialDarkTheme,
this.materialTheme,
this.builder,
this.localeResolutionCallback,
this.highContrastTheme,
this.highContrastDarkTheme,
this.localeListResolutionCallback,
this.showPerformanceOverlay = false,
this.checkerboardRasterCacheImages = false,
this.checkerboardOffscreenLayers = false,
this.showSemanticsDebugger = false,
this.debugShowMaterialGrid = false,
this.shortcuts,
this.actions,
}) : navigatorObservers = null,
navigatorKey = null,
onGenerateRoute = null,
home = null,
onGenerateInitialRoutes = null,
onUnknownRoute = null,
routes = null,
initialRoute = null,
super(key: key);

ThemeData _getMaterialTheme(NeumorphicThemeData theme) {
final color = theme.accentColor;
Expand Down Expand Up @@ -110,37 +168,68 @@ class NeumorphicApp extends StatelessWidget {
child: Builder(
builder: (context) => IconTheme(
data: NeumorphicTheme.currentTheme(context).iconTheme,
child: MaterialApp(
title: title,
color: color,
theme: materialTheme,
darkTheme: materialDarkTheme,
initialRoute: initialRoute,
routes: routes,
themeMode: themeMode,
localizationsDelegates: localizationsDelegates,
supportedLocales: supportedLocales,
locale: locale,
home: home,
onGenerateRoute: onGenerateRoute,
onUnknownRoute: onUnknownRoute,
onGenerateTitle: onGenerateTitle,
onGenerateInitialRoutes: onGenerateInitialRoutes,
navigatorKey: navigatorKey,
navigatorObservers: navigatorObservers,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
builder: builder,
localeResolutionCallback: localeResolutionCallback,
highContrastTheme: highContrastTheme,
highContrastDarkTheme: highContrastDarkTheme,
localeListResolutionCallback: localeListResolutionCallback,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
shortcuts: shortcuts,
actions: actions,
debugShowMaterialGrid: debugShowMaterialGrid),
child: _usesRouter
? MaterialApp.router(
routeInformationParser: routeInformationParser!,
routerDelegate: routerDelegate!,
routeInformationProvider: routeInformationProvider,
backButtonDispatcher: backButtonDispatcher,
title: title,
color: color,
theme: materialTheme,
darkTheme: materialDarkTheme,
themeMode: themeMode,
localizationsDelegates: localizationsDelegates,
supportedLocales: supportedLocales,
locale: locale,
onGenerateTitle: onGenerateTitle,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
builder: builder,
localeResolutionCallback: localeResolutionCallback,
highContrastTheme: highContrastTheme,
highContrastDarkTheme: highContrastDarkTheme,
localeListResolutionCallback: localeListResolutionCallback,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
shortcuts: shortcuts,
actions: actions,
debugShowMaterialGrid: debugShowMaterialGrid,
)
: MaterialApp(
title: title,
color: color,
theme: materialTheme,
darkTheme: materialDarkTheme,
initialRoute: initialRoute,
routes: routes ?? {},
themeMode: themeMode,
localizationsDelegates: localizationsDelegates,
supportedLocales: supportedLocales,
locale: locale,
home: home,
onGenerateRoute: onGenerateRoute,
onUnknownRoute: onUnknownRoute,
onGenerateTitle: onGenerateTitle,
onGenerateInitialRoutes: onGenerateInitialRoutes,
navigatorKey: navigatorKey,
navigatorObservers:
navigatorObservers ?? const <NavigatorObserver>[],
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
builder: builder,
localeResolutionCallback: localeResolutionCallback,
highContrastTheme: highContrastTheme,
highContrastDarkTheme: highContrastDarkTheme,
localeListResolutionCallback: localeListResolutionCallback,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
shortcuts: shortcuts,
actions: actions,
debugShowMaterialGrid: debugShowMaterialGrid,
),
),
),
);
Expand Down