Skip to content

Commit

Permalink
feat: platform app router support
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Oct 29, 2022
1 parent f40dc03 commit b295739
Show file tree
Hide file tree
Showing 2 changed files with 306 additions and 0 deletions.
84 changes: 84 additions & 0 deletions lib/src/platform_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:macos_ui/macos_ui.dart';
import 'package:platform_ui/src/platform_app_router.dart';
import 'package:platform_ui/src/platform_mixin.dart';
import 'package:platform_ui/src/platform_property.dart';

// TODO: Implement [PlatformTheme]

Expand Down Expand Up @@ -94,6 +96,88 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
this.useInheritedMediaQuery = false,
}) : super(key: key);

static PlatformAppRouter router({
GlobalKey<ScaffoldMessengerState>? androidScaffoldMessengerKey,
RouteInformationProvider? routeInformationProvider,
required RouteInformationParser<Object> routeInformationParser,
required RouterDelegate<Object> routerDelegate,
BackButtonDispatcher? backButtonDispatcher,
TransitionBuilder? builder,
required String title,
GenerateAppTitle? onGenerateTitle,
ThemeData? androidTheme,
ThemeData? androidDarkTheme,
CupertinoThemeData? iosTheme,
MacosThemeData? macosTheme,
MacosThemeData? macosDarkTheme,
FluentUI.ThemeData? windowsTheme,
FluentUI.ThemeData? windowsDarkTheme,
ThemeData? androidHighContrastTheme,
ThemeData? androidHghContrastDarkTheme,
ThemeMode themeMode = ThemeMode.system,
Color? color,
Locale? locale,
Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates,
LocaleListResolutionCallback? localeListResolutionCallback,
LocaleResolutionCallback? localeResolutionCallback,
PlatformProperty<Map<LogicalKeySet, Intent>>? shortcuts,
PlatformProperty<Map<Type, Action<Intent>>>? actions,
String? restorationScopeId,
PlatformProperty<ScrollBehavior>? scrollBehavior,
Iterable<Locale> supportedLocales = const <Locale>[Locale('en', 'US')],
bool showPerformanceOverlay = false,
bool checkerboardRasterCacheImages = false,
bool checkerboardOffscreenLayers = false,
bool showSemanticsDebugger = false,
bool debugShowCheckedModeBanner = true,
bool androidDebugShowMaterialGrid = false,
bool useInheritedMediaQuery = false,
}) {
return PlatformAppRouter(
androidScaffoldMessengerKey: androidScaffoldMessengerKey,
routeInformationProvider: routeInformationProvider,
routeInformationParser: routeInformationParser,
routerDelegate: routerDelegate,
backButtonDispatcher: backButtonDispatcher,
builder: builder,
title: title,
onGenerateTitle: onGenerateTitle,
androidTheme: androidTheme,
androidDarkTheme: androidDarkTheme,
iosTheme: iosTheme,
macosTheme: macosTheme,
macosDarkTheme: macosDarkTheme,
windowsTheme: windowsTheme,
windowsDarkTheme: windowsDarkTheme,
androidHighContrastTheme: androidHighContrastTheme,
androidHghContrastDarkTheme: androidHghContrastDarkTheme,
themeMode: themeMode,
color: color,
locale: locale,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts,
actions: actions,
restorationScopeId: restorationScopeId,
scrollBehavior: scrollBehavior,
androidDebugShowMaterialGrid: androidDebugShowMaterialGrid,
useInheritedMediaQuery: useInheritedMediaQuery,
localizationsDelegates: [
...(localizationsDelegates ?? []),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
FluentUI.FluentLocalizations.delegate,
],
);
}

@override
Widget android(context) {
return MaterialApp(
Expand Down
222 changes: 222 additions & 0 deletions lib/src/platform_app_router.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:macos_ui/macos_ui.dart';
import 'package:fluent_ui/fluent_ui.dart' as FluentUI;
import 'package:platform_ui/platform_ui.dart';

class PlatformAppRouter extends StatelessWidget with PlatformMixin<Widget> {
final GlobalKey<ScaffoldMessengerState>? androidScaffoldMessengerKey;
final RouteInformationProvider? routeInformationProvider;
final RouteInformationParser<Object> routeInformationParser;
final RouterDelegate<Object> routerDelegate;
final BackButtonDispatcher? backButtonDispatcher;
final TransitionBuilder? builder;
final String title;
final GenerateAppTitle? onGenerateTitle;
final ThemeData? androidTheme;
final ThemeData? androidDarkTheme;
final CupertinoThemeData? iosTheme;
final MacosThemeData? macosTheme;
final MacosThemeData? macosDarkTheme;
final FluentUI.ThemeData? windowsTheme;
final FluentUI.ThemeData? windowsDarkTheme;
final ThemeData? androidHighContrastTheme;
final ThemeData? androidHghContrastDarkTheme;
final ThemeMode? themeMode;
final Color? color;
final Locale? locale;
final Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates;
final LocaleListResolutionCallback? localeListResolutionCallback;
final LocaleResolutionCallback? localeResolutionCallback;
final Iterable<Locale> supportedLocales;
final bool showPerformanceOverlay;
final bool checkerboardRasterCacheImages;
final bool checkerboardOffscreenLayers;
final bool showSemanticsDebugger;
final bool debugShowCheckedModeBanner;
final PlatformProperty<Map<LogicalKeySet, Intent>>? shortcuts;
final PlatformProperty<Map<Type, Action<Intent>>>? actions;
final String? restorationScopeId;
final PlatformProperty<ScrollBehavior>? scrollBehavior;
final bool androidDebugShowMaterialGrid;
final bool useInheritedMediaQuery;

const PlatformAppRouter({
Key? key,
this.androidScaffoldMessengerKey,
this.routeInformationProvider,
required this.routeInformationParser,
required this.routerDelegate,
this.backButtonDispatcher,
this.builder,
this.title = '',
this.onGenerateTitle,
this.color,
this.androidTheme,
this.androidDarkTheme,
this.androidHighContrastTheme,
this.androidHghContrastDarkTheme,
this.iosTheme,
this.macosTheme,
this.macosDarkTheme,
this.windowsTheme,
this.windowsDarkTheme,
this.themeMode = ThemeMode.system,
this.locale,
this.localizationsDelegates,
this.localeListResolutionCallback,
this.localeResolutionCallback,
this.supportedLocales = const <Locale>[Locale('en', 'US')],
this.androidDebugShowMaterialGrid = false,
this.showPerformanceOverlay = false,
this.checkerboardRasterCacheImages = false,
this.checkerboardOffscreenLayers = false,
this.showSemanticsDebugger = false,
this.debugShowCheckedModeBanner = true,
this.shortcuts,
this.actions,
this.restorationScopeId,
this.scrollBehavior,
this.useInheritedMediaQuery = false,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return getPlatformType(context);
}

@override
Widget android(BuildContext context) {
return MaterialApp.router(
scaffoldMessengerKey: androidScaffoldMessengerKey,
routeInformationProvider: routeInformationProvider,
routeInformationParser: routeInformationParser,
routerDelegate: routerDelegate,
backButtonDispatcher: backButtonDispatcher,
builder: builder,
title: title,
onGenerateTitle: onGenerateTitle,
color: color,
theme: androidTheme,
darkTheme: androidDarkTheme,
highContrastTheme: androidHighContrastTheme,
highContrastDarkTheme: androidHghContrastDarkTheme,
themeMode: themeMode,
locale: locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
debugShowMaterialGrid: androidDebugShowMaterialGrid,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts?.android,
actions: actions?.android,
scrollBehavior: scrollBehavior?.android,
restorationScopeId: restorationScopeId,
useInheritedMediaQuery: useInheritedMediaQuery,
);
}

@override
Widget ios(BuildContext context) {
return CupertinoApp.router(
routeInformationProvider: routeInformationProvider,
routeInformationParser: routeInformationParser,
routerDelegate: routerDelegate,
backButtonDispatcher: backButtonDispatcher,
builder: builder,
title: title,
onGenerateTitle: onGenerateTitle,
color: color,
theme: iosTheme,
locale: locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts?.ios,
actions: actions?.ios,
scrollBehavior: scrollBehavior?.ios,
restorationScopeId: restorationScopeId,
useInheritedMediaQuery: useInheritedMediaQuery,
);
}

@override
Widget linux(BuildContext context) {
return android(context);
}

@override
Widget macos(BuildContext context) {
return MacosApp.router(
routeInformationProvider: routeInformationProvider,
routeInformationParser: routeInformationParser,
routerDelegate: routerDelegate,
backButtonDispatcher: backButtonDispatcher,
builder: builder,
title: title,
onGenerateTitle: onGenerateTitle,
color: color,
theme: macosTheme,
darkTheme: macosDarkTheme,
themeMode: themeMode,
locale: locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts?.macos,
actions: actions?.macos,
scrollBehavior: scrollBehavior?.macos ?? const MacosScrollBehavior(),
restorationScopeId: restorationScopeId,
);
}

@override
Widget windows(BuildContext context) {
return FluentUI.FluentApp.router(
routeInformationProvider: routeInformationProvider,
routeInformationParser: routeInformationParser,
routerDelegate: routerDelegate,
backButtonDispatcher: backButtonDispatcher,
builder: builder,
title: title,
onGenerateTitle: onGenerateTitle,
color: color ?? FluentUI.Colors.blue,
theme: windowsTheme,
darkTheme: windowsDarkTheme,
themeMode: themeMode,
locale: locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts?.windows,
actions: actions?.windows,
scrollBehavior:
scrollBehavior?.windows ?? const FluentUI.FluentScrollBehavior(),
restorationScopeId: restorationScopeId,
useInheritedMediaQuery: useInheritedMediaQuery,
);
}
}

0 comments on commit b295739

Please sign in to comment.