Skip to content

Commit 1452650

Browse files
committed
feat: add router constructors to PlatformSnackApp and CupertinoSnackApp
1 parent be39701 commit 1452650

File tree

2 files changed

+305
-100
lines changed

2 files changed

+305
-100
lines changed

lib/src/cupertino/cupertino_snack_app.dart

Lines changed: 110 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
44
/// A CupertinoApp that also allows to display snack bar messages
55
class CupertinoSnackApp extends StatelessWidget {
66
const CupertinoSnackApp({
7-
Key? key,
7+
super.key,
88
this.widgetKey,
99
this.navigatorKey,
1010
this.home,
@@ -34,7 +34,50 @@ class CupertinoSnackApp extends StatelessWidget {
3434
this.restorationScopeId,
3535
this.scrollBehavior,
3636
this.scaffoldMessengerKey,
37-
}) : super(key: key);
37+
}) : _isRouter = false,
38+
routeInformationParser = null,
39+
routerDelegate = null,
40+
backButtonDispatcher = null,
41+
routerConfig = null,
42+
routeInformationProvider = null;
43+
44+
const CupertinoSnackApp.router({
45+
super.key,
46+
this.widgetKey,
47+
this.routeInformationParser,
48+
this.routerDelegate,
49+
this.backButtonDispatcher,
50+
this.routerConfig,
51+
this.routeInformationProvider,
52+
this.theme,
53+
this.onGenerateTitle,
54+
this.builder,
55+
this.title = '',
56+
this.color,
57+
this.locale,
58+
this.localizationsDelegates,
59+
this.localeListResolutionCallback,
60+
this.localeResolutionCallback,
61+
this.supportedLocales = const <Locale>[Locale('en', 'US')],
62+
this.showPerformanceOverlay = false,
63+
this.checkerboardRasterCacheImages = false,
64+
this.checkerboardOffscreenLayers = false,
65+
this.showSemanticsDebugger = false,
66+
this.debugShowCheckedModeBanner = true,
67+
this.shortcuts,
68+
this.actions,
69+
this.restorationScopeId,
70+
this.scrollBehavior,
71+
this.scaffoldMessengerKey,
72+
}) : _isRouter = true,
73+
navigatorKey = null,
74+
home = null,
75+
initialRoute = null,
76+
onGenerateRoute = null,
77+
onGenerateInitialRoutes = null,
78+
onUnknownRoute = null,
79+
routes = const <String, WidgetBuilder>{},
80+
navigatorObservers = const <NavigatorObserver>[];
3881

3982
final Key? widgetKey;
4083
final GlobalKey<NavigatorState>? navigatorKey;
@@ -66,39 +109,74 @@ class CupertinoSnackApp extends StatelessWidget {
66109
final String? restorationScopeId;
67110
final ScrollBehavior? scrollBehavior;
68111
final GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey;
112+
final RouteInformationProvider? routeInformationProvider;
113+
final RouteInformationParser<Object>? routeInformationParser;
114+
final RouterDelegate<Object>? routerDelegate;
115+
final BackButtonDispatcher? backButtonDispatcher;
116+
final RouterConfig<Object>? routerConfig;
117+
118+
final bool _isRouter;
69119

70120
@override
71121
Widget build(BuildContext context) {
72-
return CupertinoApp(
73-
key: widgetKey,
74-
navigatorKey: navigatorKey,
75-
navigatorObservers: navigatorObservers,
76-
home: home,
77-
theme: theme,
78-
routes: routes,
79-
initialRoute: initialRoute,
80-
onGenerateRoute: onGenerateRoute,
81-
onGenerateInitialRoutes: onGenerateInitialRoutes,
82-
onUnknownRoute: onUnknownRoute,
83-
builder: _build,
84-
title: title,
85-
onGenerateTitle: onGenerateTitle,
86-
color: color,
87-
locale: locale,
88-
localizationsDelegates: localizationsDelegates,
89-
localeResolutionCallback: localeResolutionCallback,
90-
localeListResolutionCallback: localeListResolutionCallback,
91-
supportedLocales: supportedLocales,
92-
showPerformanceOverlay: showPerformanceOverlay,
93-
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
94-
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
95-
showSemanticsDebugger: showSemanticsDebugger,
96-
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
97-
shortcuts: shortcuts,
98-
actions: actions,
99-
restorationScopeId: restorationScopeId,
100-
scrollBehavior: scrollBehavior,
101-
);
122+
return _isRouter
123+
? CupertinoApp.router(
124+
key: widgetKey,
125+
theme: theme,
126+
routerConfig: routerConfig,
127+
routeInformationParser: routeInformationParser,
128+
routeInformationProvider: routeInformationProvider,
129+
routerDelegate: routerDelegate,
130+
backButtonDispatcher: backButtonDispatcher,
131+
builder: _build,
132+
title: title,
133+
onGenerateTitle: onGenerateTitle,
134+
color: color,
135+
locale: locale,
136+
localizationsDelegates: localizationsDelegates,
137+
localeResolutionCallback: localeResolutionCallback,
138+
localeListResolutionCallback: localeListResolutionCallback,
139+
supportedLocales: supportedLocales,
140+
showPerformanceOverlay: showPerformanceOverlay,
141+
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
142+
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
143+
showSemanticsDebugger: showSemanticsDebugger,
144+
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
145+
shortcuts: shortcuts,
146+
actions: actions,
147+
restorationScopeId: restorationScopeId,
148+
scrollBehavior: scrollBehavior,
149+
)
150+
: CupertinoApp(
151+
key: widgetKey,
152+
navigatorKey: navigatorKey,
153+
navigatorObservers: navigatorObservers,
154+
home: home,
155+
theme: theme,
156+
routes: routes,
157+
initialRoute: initialRoute,
158+
onGenerateRoute: onGenerateRoute,
159+
onGenerateInitialRoutes: onGenerateInitialRoutes,
160+
onUnknownRoute: onUnknownRoute,
161+
builder: _build,
162+
title: title,
163+
onGenerateTitle: onGenerateTitle,
164+
color: color,
165+
locale: locale,
166+
localizationsDelegates: localizationsDelegates,
167+
localeResolutionCallback: localeResolutionCallback,
168+
localeListResolutionCallback: localeListResolutionCallback,
169+
supportedLocales: supportedLocales,
170+
showPerformanceOverlay: showPerformanceOverlay,
171+
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
172+
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
173+
showSemanticsDebugger: showSemanticsDebugger,
174+
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
175+
shortcuts: shortcuts,
176+
actions: actions,
177+
restorationScopeId: restorationScopeId,
178+
scrollBehavior: scrollBehavior,
179+
);
102180
}
103181

104182
Widget _build(BuildContext context, Widget? child) {

0 commit comments

Comments
 (0)