-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropdown_menu_button.dart
46 lines (40 loc) · 1.58 KB
/
dropdown_menu_button.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
import 'package:flutter/material.dart';
class DropdownMenuButton extends StatelessWidget {
const DropdownMenuButton({
super.key,
this.child,
this.titleString,
required this.menuChildren,
this.isFormInput = true,
});
final Widget? child;
final String? titleString;
final List<Widget> menuChildren;
final bool isFormInput;
static final FocusNode _buttonFocusNode = FocusNode(debugLabel: '_buttonFocusNode');
@override
Widget build(BuildContext context) => _build(context);
Widget _build(BuildContext context) => MenuAnchor(
childFocusNode: _buttonFocusNode,
menuChildren: menuChildren,
crossAxisUnconstrained: false,
builder: (context, controller, _) => OutlinedButton.icon(
style: OutlinedButton.styleFrom(tapTargetSize: MaterialTapTargetSize.shrinkWrap),
focusNode: _buttonFocusNode,
onPressed: () => controller.isOpen ? controller.close() : controller.open(),
icon: Icon(
controller.isOpen ? Icons.keyboard_arrow_up_rounded : Icons.keyboard_arrow_down_rounded,
),
iconAlignment: IconAlignment.end,
label: child ?? _buildTitle(titleString ?? '', context),
),
);
Widget _buildTitle(String text, BuildContext context) => isFormInput
? Row(children: [
Padding(
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: Text(text, style: Theme.of(context).textTheme.titleSmall?.copyWith(color: Colors.black)),
)
])
: Text(text, style: Theme.of(context).textTheme.labelLarge);
}