@@ -3,92 +3,153 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
33
44import '../../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}
0 commit comments