radial_menu_item.dart
2.1 KB
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
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
const double _defaultButtonSize = 48.0;
/// An item in a [RadialMenu].
///
/// The type `T` is the type of the value the entry represents. All the entries
/// in a given menu must represent values with consistent types.
class RadialMenuItem<T> extends StatelessWidget {
/// Creates a circular action button for an item in a [RadialMenu].
///
/// The [child] argument is required.
const RadialMenuItem({
Key? key,
required this.child,
required this.value,
required this.tooltip,
this.size = _defaultButtonSize,
required this.backgroundColor,
required this.iconColor,
this.iconSize = 24.0,
}) : super(key: key);
/// The widget below this widget in the tree.
///
/// Typically an [Icon] widget.
final Widget child;
/// The value to return if the user selects this menu item.
///
/// Eventually returned in a call to [RadialMenu.onSelected].
final T value;
/// Text that describes the action that will occur when the button is pressed.
///
/// This text is displayed when the user long-presses on the button and is
/// used for accessibility.
final String tooltip;
/// The color to use when filling the button.
///
/// Defaults to the primary color of the current theme.
final Color backgroundColor;
/// The size of the button.
///
/// Defaults to 48.0.
final double size;
/// The color to use when painting the child icon.
///
/// Defaults to the primary icon theme color.
final Color? iconColor;
final double? iconSize;
@override
Widget build(BuildContext context) {
final Color? _iconColor =
iconColor ?? Theme.of(context).primaryIconTheme.color;
late Widget result;
result = Center(
child: IconTheme.merge(
data: IconThemeData(
color: _iconColor,
size: iconSize,
),
child: child,
),
);
result = Tooltip(
message: tooltip,
child: result,
);
result = SizedBox(
width: size,
height: size,
child: result,
);
return result;
}
}