|
| 1 | +import 'package:flutter/cupertino.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'dart:io' show Platform; |
| 4 | + |
| 5 | +class PlatformApp extends StatefulWidget { |
| 6 | + PlatformApp({ |
| 7 | + this.navigatorKey, |
| 8 | + this.home, |
| 9 | + this.routes, |
| 10 | + this.initialRoute, |
| 11 | + this.onGenerateRoute, |
| 12 | + this.onUnknownRoute, |
| 13 | + this.navigatorObservers, |
| 14 | + this.builder, |
| 15 | + this.title, |
| 16 | + this.onGenerateTitle, |
| 17 | + this.color, |
| 18 | + this.locale, |
| 19 | + this.localizationsDelegates, |
| 20 | + this.localeListResolutionCallback, |
| 21 | + this.localeResolutionCallback, |
| 22 | + this.supportedLocales, |
| 23 | + this.showPerformanceOverlay, |
| 24 | + this.checkerboardRasterCacheImages, |
| 25 | + this.checkerboardOffscreenLayers, |
| 26 | + this.showSemanticsDebugger, |
| 27 | + this.debugShowCheckedModeBanner, |
| 28 | + this.shortcuts, |
| 29 | + this.actions, |
| 30 | + }); |
| 31 | + |
| 32 | + final GlobalKey<NavigatorState> navigatorKey; |
| 33 | + final Widget home; |
| 34 | + final Map<String, WidgetBuilder> routes; |
| 35 | + final String initialRoute; |
| 36 | + final RouteFactory onGenerateRoute; |
| 37 | + final RouteFactory onUnknownRoute; |
| 38 | + final List<NavigatorObserver> navigatorObservers; |
| 39 | + final TransitionBuilder builder; |
| 40 | + final String title; |
| 41 | + final GenerateAppTitle onGenerateTitle; |
| 42 | + final Color color; |
| 43 | + final Locale locale; |
| 44 | + final Iterable<LocalizationsDelegate<dynamic>> localizationsDelegates; |
| 45 | + final LocaleListResolutionCallback localeListResolutionCallback; |
| 46 | + final LocaleResolutionCallback localeResolutionCallback; |
| 47 | + final Iterable<Locale> supportedLocales; |
| 48 | + final bool showPerformanceOverlay; |
| 49 | + final bool checkerboardRasterCacheImages; |
| 50 | + final bool checkerboardOffscreenLayers; |
| 51 | + final bool showSemanticsDebugger; |
| 52 | + final bool debugShowCheckedModeBanner; |
| 53 | + final Map<LogicalKeySet, Intent> shortcuts; |
| 54 | + final Map<LocalKey, ActionFactory> actions; |
| 55 | + |
| 56 | + CupertinoApp createIosApp(BuildContext context) { |
| 57 | + return CupertinoApp( |
| 58 | + navigatorKey: navigatorKey, |
| 59 | + home: home, |
| 60 | + routes: routes, |
| 61 | + initialRoute: initialRoute, |
| 62 | + onGenerateRoute: onGenerateRoute, |
| 63 | + onUnknownRoute: onUnknownRoute, |
| 64 | + navigatorObservers: navigatorObservers, |
| 65 | + builder: builder, |
| 66 | + title: title, |
| 67 | + onGenerateTitle: onGenerateTitle, |
| 68 | + color: color, |
| 69 | + locale: locale, |
| 70 | + localizationsDelegates: localizationsDelegates, |
| 71 | + localeListResolutionCallback: localeListResolutionCallback, |
| 72 | + localeResolutionCallback: localeResolutionCallback, |
| 73 | + supportedLocales: supportedLocales, |
| 74 | + showPerformanceOverlay: showPerformanceOverlay, |
| 75 | + checkerboardRasterCacheImages: checkerboardRasterCacheImages, |
| 76 | + checkerboardOffscreenLayers: checkerboardOffscreenLayers, |
| 77 | + showSemanticsDebugger: showSemanticsDebugger, |
| 78 | + debugShowCheckedModeBanner: debugShowCheckedModeBanner, |
| 79 | + shortcuts: shortcuts, |
| 80 | + actions: actions, |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + MaterialApp createAndroidApp(BuildContext context) { |
| 85 | + return MaterialApp( |
| 86 | + navigatorKey: navigatorKey, |
| 87 | + home: home, |
| 88 | + routes: routes, |
| 89 | + initialRoute: initialRoute, |
| 90 | + onGenerateRoute: onGenerateRoute, |
| 91 | + onUnknownRoute: onUnknownRoute, |
| 92 | + navigatorObservers: navigatorObservers, |
| 93 | + builder: builder, |
| 94 | + title: title, |
| 95 | + onGenerateTitle: onGenerateTitle, |
| 96 | + color: color, |
| 97 | + locale: locale, |
| 98 | + localizationsDelegates: localizationsDelegates, |
| 99 | + localeListResolutionCallback: localeListResolutionCallback, |
| 100 | + localeResolutionCallback: localeResolutionCallback, |
| 101 | + supportedLocales: supportedLocales, |
| 102 | + showPerformanceOverlay: showPerformanceOverlay, |
| 103 | + checkerboardRasterCacheImages: checkerboardRasterCacheImages, |
| 104 | + checkerboardOffscreenLayers: checkerboardOffscreenLayers, |
| 105 | + showSemanticsDebugger: showSemanticsDebugger, |
| 106 | + debugShowCheckedModeBanner: debugShowCheckedModeBanner, |
| 107 | + shortcuts: shortcuts, |
| 108 | + actions: actions, |
| 109 | + ); |
| 110 | + } |
| 111 | + |
| 112 | + @override |
| 113 | + _PlatformAppState createState() => _PlatformAppState( |
| 114 | + createIosApp: (context) => createIosApp(context), |
| 115 | + createAndroidApp: (context) => createAndroidApp(context), |
| 116 | + ); |
| 117 | +} |
| 118 | + |
| 119 | +class _PlatformAppState<I, A> extends State<PlatformApp> { |
| 120 | + _PlatformAppState({ |
| 121 | + @required this.createIosApp, |
| 122 | + @required this.createAndroidApp, |
| 123 | + }); |
| 124 | + |
| 125 | + Function createIosApp; |
| 126 | + Function createAndroidApp; |
| 127 | + |
| 128 | + @override |
| 129 | + Widget build(BuildContext context) { |
| 130 | + if (Platform.isIOS) { |
| 131 | + return this.createIosApp(context); |
| 132 | + } else if (Platform.isAndroid) { |
| 133 | + return this.createAndroidApp(context); |
| 134 | + } |
| 135 | + return Container(); |
| 136 | + } |
| 137 | +} |
0 commit comments