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

add NeumorphicApp.router for MaterialApp.router ? #245

Open
OHeroJ opened this issue Nov 17, 2021 · 2 comments
Open

add NeumorphicApp.router for MaterialApp.router ? #245

OHeroJ opened this issue Nov 17, 2021 · 2 comments

Comments

@OHeroJ
Copy link

OHeroJ commented Nov 17, 2021

No description provided.

@OHeroJ
Copy link
Author

OHeroJ commented Nov 17, 2021

class MyNeumorphicApp extends StatelessWidget {
  final String title;
  final ThemeMode themeMode;
  final NeumorphicThemeData theme;
  final NeumorphicThemeData darkTheme;
  final ThemeData? materialDarkTheme;
  final ThemeData? materialTheme;
  final String? initialRoute;
  final Color? color;
  final Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates;
  final Locale? locale;
  final Widget? home;
  final Iterable<Locale> supportedLocales;
  final Map<String, WidgetBuilder> routes;
  final RouteFactory? onGenerateRoute;
  final RouteFactory? onUnknownRoute;
  final GenerateAppTitle? onGenerateTitle;
  final GlobalKey<NavigatorState>? navigatorKey;
  final List<NavigatorObserver> navigatorObservers;
  final InitialRouteListFactory? onGenerateInitialRoutes;
  final bool debugShowCheckedModeBanner;
  final Widget Function(BuildContext, Widget?)? builder;
  final Locale? Function(Locale?, Iterable<Locale>)? localeResolutionCallback;
  final ThemeData? highContrastTheme;
  final ThemeData? highContrastDarkTheme;
  final LocaleListResolutionCallback? localeListResolutionCallback;
  final bool showPerformanceOverlay;
  final bool checkerboardRasterCacheImages;
  final bool checkerboardOffscreenLayers;
  final bool showSemanticsDebugger;
  final Map<LogicalKeySet, Intent>? shortcuts;
  final Map<Type, Action<Intent>>? actions;

  final bool debugShowMaterialGrid;

  final RouteInformationParser<Object>? routeInformationParser;
  final RouterDelegate<Object>? routerDelegate;
  final RouteInformationProvider? routeInformationProvider;

  const MyNeumorphicApp({
    Key? key,
    this.title = '',
    this.color,
    this.initialRoute,
    this.routes = const {},
    this.home,
    this.debugShowCheckedModeBanner = true,
    this.navigatorKey,
    this.navigatorObservers = const [],
    this.onGenerateRoute,
    this.onGenerateTitle,
    this.onGenerateInitialRoutes,
    this.onUnknownRoute,
    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,
    this.routeInformationParser,
    this.routerDelegate,
    this.routeInformationProvider,
  }) : super(key: key);

  ThemeData _getMaterialTheme(NeumorphicThemeData theme) {
    final color = theme.accentColor;

    if (color is MaterialColor) {
      return ThemeData(
        primarySwatch: color,
        textTheme: theme.textTheme,
        iconTheme: theme.iconTheme,
        scaffoldBackgroundColor: theme.baseColor,
      );
    }

    return ThemeData(
      primaryColor: theme.accentColor,
      accentColor: theme.variantColor,
      iconTheme: theme.iconTheme,
      brightness: ThemeData.estimateBrightnessForColor(theme.baseColor),
      primaryColorBrightness:
          ThemeData.estimateBrightnessForColor(theme.accentColor),
      accentColorBrightness:
          ThemeData.estimateBrightnessForColor(theme.variantColor),
      textTheme: theme.textTheme,
      scaffoldBackgroundColor: theme.baseColor,
    );
  }

  @override
  Widget build(BuildContext context) {
    final materialTheme = this.materialTheme ?? _getMaterialTheme(theme);
    final materialDarkTheme =
        this.materialDarkTheme ?? _getMaterialTheme(darkTheme);

    return NeumorphicTheme(
      theme: theme,
      darkTheme: darkTheme,
      themeMode: themeMode,
      child: Builder(
        builder: (context) => IconTheme(
          data: NeumorphicTheme.currentTheme(context).iconTheme,
          child: buildMaterialApp(materialTheme, materialDarkTheme),
        ),
      ),
    );
  }

  MaterialApp buildMaterialApp(
      ThemeData materialTheme, ThemeData materialDarkTheme) {
    if (routeInformationParser != null && routerDelegate != null) {
      return MaterialApp.router(
        routeInformationParser: routeInformationParser!,
        routerDelegate: routerDelegate!,
        routeInformationProvider: routeInformationProvider,
        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,
      );
    } else {
      return 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,
      );
    }
  }
}

@MrKnos
Copy link

MrKnos commented Jul 27, 2022

Fixed at this PR (waiting for merge).

or use it by adding below in pubspec.yaml.

dependency_overrides:
  flutter_neumorphic:
    git:
      url: git@github.com:MrKnos/Flutter-Neumorphic.git
      ref: feature/neumorphic-app-router

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants