Skip to content

Commit d681809

Browse files
committed
2 parents 8e95406 + 8a971f5 commit d681809

File tree

5 files changed

+131
-62
lines changed

5 files changed

+131
-62
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ doc/api/
1919
*.js_
2020
*.js.deps
2121
*.js.map
22+
23+
*.iml
24+
.vscode
25+
.idea

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Platform widgets use their material or cupertino equivalent based on the chosen
1919
* `PlatformChip` a simple cross-platform `Chip` replacement
2020
* `PlatformDialogActionButton` is a platform aware dialog action
2121
* `PlatformDialogActionText` provides a platform aware dialog action text
22-
* `DropdownButton` is a replacement for the material `DropdownButton`
22+
* `PlatformDropdownButton` is a replacement for the material `DropdownButton`
2323
* `PlatformFilledButtonIcon` uses an `ElevatedButton.filled` on material and a `CupertinoButton.filled` on cupertino
2424
* `DensePlatformIconButton` replaces the material `IconButton`
2525
* `PlatformInkWell` is a rectangular area of a that responds to touch and is based either on `InkWell` or on `CupertinoInkWell`

lib/src/cupertino/cupertino_dropdown_button.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class CupertinoDropdownButton<T> extends StatefulWidget {
1212
final void Function(T? value)? onChanged;
1313
final double itemExtent;
1414
final Widget? hint;
15+
final double? width;
16+
final double? height;
1517

1618
const CupertinoDropdownButton({
1719
Key? key,
@@ -21,6 +23,8 @@ class CupertinoDropdownButton<T> extends StatefulWidget {
2123
this.onChanged,
2224
this.hint,
2325
required this.itemExtent,
26+
this.width,
27+
this.height,
2428
}) : super(key: key);
2529

2630
@override
@@ -71,8 +75,8 @@ class _CupertinoDropdownButtonState<T>
7175
final result = await showCupertinoModalPopup<bool>(
7276
context: context,
7377
builder: (context) => SizedBox(
74-
width: MediaQuery.of(context).size.width,
75-
height: MediaQuery.of(context).size.height * 0.7,
78+
width: widget.width ?? MediaQuery.of(context).size.width,
79+
height: widget.height ?? MediaQuery.of(context).size.height * 0.7,
7680
child: SafeArea(
7781
child: Container(
7882
color: CupertinoTheme.of(context).barBackgroundColor,

lib/src/platform/platform_dropdown_button.dart

Lines changed: 119 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,92 +3,153 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
33

44
import '../../cupertino.dart';
55

6-
/// A platform aware DropdownButton
7-
class PlatformDropdownButton<T> extends StatelessWidget {
6+
abstract class _BaseData<T> {
7+
_BaseData({
8+
this.items,
9+
this.selectedItemBuilder,
10+
this.value,
11+
this.itemHeight,
12+
this.hint,
13+
this.onChanged
14+
});
15+
816
final List<DropdownMenuItem<T>>? items;
917
final List<Widget> Function(BuildContext context)? selectedItemBuilder;
1018
final T? value;
19+
final double? itemHeight;
1120
final Widget? hint;
12-
final Widget? disabledHint;
1321
final void Function(T? value)? onChanged;
22+
}
23+
24+
class MaterialDropdownButtonData<T> extends _BaseData<T> {
25+
MaterialDropdownButtonData({
26+
super.items,
27+
super.selectedItemBuilder,
28+
super.value,
29+
super.itemHeight,
30+
super.hint,
31+
super.onChanged,
32+
this.disabledHint,
33+
this.onTap,
34+
this.elevation,
35+
this.style,
36+
this.underline,
37+
this.icon,
38+
this.iconDisabledColor,
39+
this.iconEnabledColor,
40+
this.iconSize,
41+
this.isDense,
42+
this.isExpanded,
43+
this.focusColor,
44+
this.focusNode,
45+
this.autofocus,
46+
this.dropdownColor,
47+
this.menuMaxHeight,
48+
});
49+
50+
final Widget? disabledHint;
1451
final void Function()? onTap;
15-
final int elevation;
52+
final int? elevation;
1653
final TextStyle? style;
1754
final Widget? underline;
1855
final Widget? icon;
1956
final Color? iconDisabledColor;
2057
final Color? iconEnabledColor;
21-
final double iconSize;
22-
final bool isDense;
23-
final bool isExpanded;
24-
final double? itemHeight;
58+
final double? iconSize;
59+
final bool? isDense;
60+
final bool? isExpanded;
2561
final Color? focusColor;
2662
final FocusNode? focusNode;
27-
final bool autofocus;
63+
final bool? autofocus;
2864
final Color? dropdownColor;
2965
final double? menuMaxHeight;
66+
}
67+
68+
class CupertinoDropdownButtonData<T> extends _BaseData<T> {
69+
CupertinoDropdownButtonData({
70+
super.items,
71+
super.selectedItemBuilder,
72+
super.value,
73+
super.itemHeight,
74+
super.hint,
75+
super.onChanged,
76+
this.width,
77+
this.height
78+
});
79+
80+
final double? width;
81+
final double? height;
82+
}
83+
84+
/// A platform aware DropdownButton
85+
class PlatformDropdownButton<T> extends StatelessWidget {
86+
final List<DropdownMenuItem<T>>? items;
87+
final List<Widget> Function(BuildContext context)? selectedItemBuilder;
88+
final T? value;
89+
final double? itemHeight;
90+
final Widget? hint;
91+
final void Function(T? value)? onChanged;
92+
93+
final PlatformBuilder<MaterialDropdownButtonData<T>>? material;
94+
final PlatformBuilder<CupertinoDropdownButtonData<T>>? cupertino;
3095

3196
const PlatformDropdownButton({
3297
Key? key,
3398
required this.items,
3499
this.selectedItemBuilder,
35100
this.value,
36101
this.hint,
37-
this.disabledHint,
38102
this.onChanged,
39-
this.onTap,
40-
this.elevation = 8,
41-
this.style,
42-
this.underline,
43-
this.icon,
44-
this.iconDisabledColor,
45-
this.iconEnabledColor,
46-
this.iconSize = 24.0,
47-
this.isDense = false,
48-
this.isExpanded = false,
49-
this.itemHeight = kMinInteractiveDimension,
50-
this.focusColor,
51-
this.focusNode,
52-
this.autofocus = false,
53-
this.dropdownColor,
54-
this.menuMaxHeight,
103+
this.itemHeight,
104+
this.material,
105+
this.cupertino,
55106
}) : super(key: key);
56107

57108
@override
58109
Widget build(BuildContext context) {
59110
return PlatformWidget(
60-
material: (context, platform) => DropdownButton<T>(
61-
items: items,
62-
selectedItemBuilder: selectedItemBuilder,
63-
value: value,
64-
hint: hint,
65-
disabledHint: disabledHint,
66-
onChanged: onChanged,
67-
onTap: onTap,
68-
elevation: elevation,
69-
style: style,
70-
underline: underline,
71-
icon: icon,
72-
iconDisabledColor: iconDisabledColor,
73-
iconEnabledColor: iconEnabledColor,
74-
iconSize: iconSize,
75-
isDense: isDense,
76-
isExpanded: isExpanded,
77-
itemHeight: itemHeight,
78-
focusColor: focusColor,
79-
focusNode: focusNode,
80-
autofocus: autofocus,
81-
dropdownColor: dropdownColor,
82-
menuMaxHeight: menuMaxHeight,
83-
),
84-
cupertino: (context, platform) => CupertinoDropdownButton(
85-
items: items,
86-
selectedItemBuilder: selectedItemBuilder,
87-
value: value,
88-
itemExtent: itemHeight ?? 12.0,
89-
hint: hint,
90-
onChanged: onChanged,
91-
),
111+
material: (context, platform) {
112+
final data = material?.call(context, platform);
113+
114+
return DropdownButton<T>(
115+
items: data?.items ?? items ?? <DropdownMenuItem<T>>[],
116+
selectedItemBuilder: data?.selectedItemBuilder ?? selectedItemBuilder,
117+
value: data?.value ?? value,
118+
hint: data?.hint ?? hint,
119+
onChanged: data?.onChanged ?? onChanged,
120+
itemHeight: data?.itemHeight ?? itemHeight ?? kMinInteractiveDimension,
121+
disabledHint: data?.disabledHint,
122+
onTap: data?.onTap,
123+
elevation: data?.elevation ?? 8,
124+
style: data?.style,
125+
underline: data?.underline,
126+
icon: data?.icon,
127+
iconDisabledColor: data?.iconDisabledColor,
128+
iconEnabledColor: data?.iconEnabledColor,
129+
iconSize: data?.iconSize ?? 24.0,
130+
isDense: data?.isDense ?? false,
131+
isExpanded: data?.isExpanded ?? false,
132+
focusColor: data?.focusColor,
133+
focusNode: data?.focusNode,
134+
autofocus: data?.autofocus ?? false,
135+
dropdownColor: data?.dropdownColor,
136+
menuMaxHeight: data?.menuMaxHeight,
137+
);
138+
},
139+
cupertino: (context, platform) {
140+
final data = cupertino?.call(context, platform);
141+
142+
return CupertinoDropdownButton(
143+
items: data?.items ?? items,
144+
selectedItemBuilder: data?.selectedItemBuilder ?? selectedItemBuilder,
145+
value: data?.value ?? value,
146+
itemExtent: data?.itemHeight ?? itemHeight ?? 12.0,
147+
hint: data?.hint ?? hint,
148+
onChanged: data?.onChanged ?? onChanged,
149+
width: data?.width,
150+
height: data?.height,
151+
);
152+
},
92153
);
93154
}
94155
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 0.6.0
44
homepage: https://github.com/Enough-Software/enough_platform_widgets
55

66
environment:
7-
sdk: ">=2.12.0 <3.0.0"
7+
sdk: ">=2.17.0 <3.0.0"
88
flutter: ">=1.17.0"
99

1010
dependencies:

0 commit comments

Comments
 (0)