buildByMaterial method
build on material mode
Implementation
@override
Widget buildByMaterial(BuildContext context) {
final theme = Theme.of(context);
return PopupMenuButton<int>(
itemBuilder: (context) {
final menuItems = <PopupMenuEntry<int>>[];
int itemIndex = 0;
for (final entry in items) {
if (entry is CNPullDownMenuItem) {
menuItems.add(
PopupMenuItem<int>(
value: itemIndex++,
child: Row(
children: [
if (entry.icon != null) ...[
Icon(Icons.circle, size: 20, color: theme.colorScheme.primary),
const SizedBox(width: 12),
],
Text(entry.label),
],
),
),
);
} else if (entry is CNPullDownMenuDivider) {
menuItems.add(const PopupMenuDivider());
}
}
return menuItems;
},
onSelected: onSelected,
child: buttonIcon != null
? Container(
width: size,
height: size,
decoration: BoxDecoration(
color: _getBackgroundColor(theme),
borderRadius: BorderRadius.circular(size / 2),
border: buttonStyle == CNButtonStyle.bordered
? Border.all(color: tint ?? theme.colorScheme.primary)
: null,
),
child: Icon(
Icons.more_horiz,
color: _getIconColor(theme),
size: size * 0.5,
),
)
: Container(
height: height,
width: width,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: _getBackgroundColor(theme),
borderRadius: BorderRadius.circular(8),
border: buttonStyle == CNButtonStyle.bordered
? Border.all(color: tint ?? theme.colorScheme.primary)
: null,
),
child: Row(
mainAxisSize: width == null ? MainAxisSize.min : MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
buttonLabel ?? '',
style: TextStyle(
color: _getTextColor(theme),
fontWeight: FontWeight.w500,
),
),
const SizedBox(width: 4),
Icon(
Icons.arrow_drop_down,
color: _getTextColor(theme),
size: 20,
),
],
),
),
);
}