/
platform_adaptive.dart
92 lines (81 loc) · 2.46 KB
/
platform_adaptive.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2017, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
final ThemeData kIOSTheme = new ThemeData(
primarySwatch: Colors.orange,
primaryColor: Colors.grey[100],
primaryColorBrightness: Brightness.light,
);
final ThemeData kDefaultTheme = new ThemeData(
primarySwatch: Colors.purple,
accentColor: Colors.orangeAccent[400],
);
/// App bar that uses iOS styling on iOS
class PlatformAdaptiveAppBar extends AppBar {
PlatformAdaptiveAppBar({
Key key,
TargetPlatform platform,
List<Widget> actions,
Widget title,
Widget body,
// TODO(jackson): other properties?
})
: super(
key: key,
elevation: platform == TargetPlatform.iOS ? 0.0 : 4.0,
title: title,
actions: actions,
);
}
/// Button that is Material on Android and Cupertino on iOS
/// On Android an icon button; on iOS, text is used
class PlatformAdaptiveButton extends StatelessWidget {
PlatformAdaptiveButton({Key key, this.child, this.icon, this.onPressed})
: super(key: key);
final Widget child;
final Widget icon;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
if (Theme.of(context).platform == TargetPlatform.iOS) {
return new CupertinoButton(
child: child,
onPressed: onPressed,
);
} else {
return new IconButton(
icon: icon,
onPressed: onPressed,
);
}
}
}
class PlatformAdaptiveContainer extends StatelessWidget {
final Widget child;
final EdgeInsets margin;
PlatformAdaptiveContainer({Key key, this.child, this.margin})
: super(key: key);
@override
Widget build(BuildContext context) {
return new Container(
child: child,
margin: margin,
decoration: Theme.of(context).platform == TargetPlatform.iOS
? new BoxDecoration(
border: new Border(top: new BorderSide(color: Colors.grey[200])))
: null,
);
}
}
class PlatformChooser extends StatelessWidget {
PlatformChooser({Key key, this.iosChild, this.defaultChild});
final Widget iosChild;
final Widget defaultChild;
@override
Widget build(BuildContext context) {
if (Theme.of(context).platform == TargetPlatform.iOS) return iosChild;
return defaultChild;
}
}