Skip to content

Commit 1e7e7e7

Browse files
authored
Merge pull request #3 from Flutterista/develop
Release 0.0.1
2 parents a3de2bf + 0338409 commit 1e7e7e7

13 files changed

+627
-1
lines changed

.gitignore

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
.dart_tool/
26+
.flutter-plugins
27+
.flutter-plugins-dependencies
28+
.packages
29+
.pub-cache/
30+
.pub/
31+
build/
32+
33+
# Android related
34+
**/android/**/gradle-wrapper.jar
35+
**/android/.gradle
36+
**/android/captures/
37+
**/android/gradlew
38+
**/android/gradlew.bat
39+
**/android/local.properties
40+
**/android/**/GeneratedPluginRegistrant.java
41+
42+
# iOS/XCode related
43+
**/ios/**/*.mode1v3
44+
**/ios/**/*.mode2v3
45+
**/ios/**/*.moved-aside
46+
**/ios/**/*.pbxuser
47+
**/ios/**/*.perspectivev3
48+
**/ios/**/*sync/
49+
**/ios/**/.sconsign.dblite
50+
**/ios/**/.tags*
51+
**/ios/**/.vagrant/
52+
**/ios/**/DerivedData/
53+
**/ios/**/Icon?
54+
**/ios/**/Pods/
55+
**/ios/**/.symlinks/
56+
**/ios/**/profile
57+
**/ios/**/xcuserdata
58+
**/ios/.generated/
59+
**/ios/Flutter/App.framework
60+
**/ios/Flutter/Flutter.framework
61+
**/ios/Flutter/Flutter.podspec
62+
**/ios/Flutter/Generated.xcconfig
63+
**/ios/Flutter/app.flx
64+
**/ios/Flutter/app.zip
65+
**/ios/Flutter/flutter_assets/
66+
**/ios/Flutter/flutter_export_environment.sh
67+
**/ios/ServiceDefinitions.json
68+
**/ios/Runner/GeneratedPluginRegistrant.*
69+
70+
# Exceptions to above rules.
71+
!**/ios/**/default.mode1v3
72+
!**/ios/**/default.mode2v3
73+
!**/ios/**/default.pbxuser
74+
!**/ios/**/default.perspectivev3
75+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: ab36346af6e6c61ab4174c753b1ec3f3260fa56a
8+
channel: master
9+
10+
project_type: package

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## [0.0.1] - 16/01/2020
2+
3+
- Initial structure
4+
- PlatformApp and PlatformScaffold Widgets

LICENSE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright 2020 The Flutterista Authors. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
5+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
7+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8+
9+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10+
11+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
# platform_widgets
1+
# Platform Widgets
2+
3+
![Flutter](https://img.shields.io/badge/sdk-Flutter-9cf)
4+
![Dart](https://img.shields.io/badge/language-Dart-blue)
5+
6+
A Flutter plugin for Platform specific widgets.
7+
8+
## Usage
9+
To use this plugin, add platform_widgets as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
10+
11+
## Available Widgets
12+
13+
- `PlatformApp` returns **CupertinoApp** when iOS and **MaterialApp** when Android.
14+
15+
- `PlatformScaffold` returns **CupertinoPageScaffold** when iOS and **Scaffold** when Android.
16+
17+

lib/base/platform_app.dart

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
}

lib/base/platform_widget.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
import 'dart:io' show Platform;
4+
5+
abstract class PlatformWidget<I extends Widget, A extends Widget>
6+
extends StatelessWidget {
7+
8+
I createIosWidget(BuildContext context);
9+
A createAndroidWidget(BuildContext context);
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
if (Platform.isAndroid) {
14+
return createAndroidWidget(context);
15+
} else if (Platform.isIOS) {
16+
return createIosWidget(context);
17+
}
18+
return Container();
19+
}
20+
}

lib/platform_scaffold.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:platform_widgets/base/platform_widget.dart';
2+
import 'package:flutter/cupertino.dart';
3+
import 'package:flutter/material.dart';
4+
5+
class PlatformScaffold extends PlatformWidget<CupertinoPageScaffold, Scaffold> {
6+
PlatformScaffold({this.title, this.child, this.appbar, this.backgroundColor});
7+
8+
final String title;
9+
final Widget child;
10+
final Widget appbar;
11+
final Color backgroundColor;
12+
13+
@override
14+
CupertinoPageScaffold createIosWidget(BuildContext context) {
15+
return CupertinoPageScaffold(
16+
navigationBar: appbar,
17+
child: child,
18+
backgroundColor: backgroundColor,
19+
);
20+
}
21+
22+
@override
23+
Scaffold createAndroidWidget(BuildContext context) {
24+
return Scaffold(
25+
appBar: appbar,
26+
body: child,
27+
backgroundColor: backgroundColor,
28+
);
29+
}
30+
}

0 commit comments

Comments
 (0)