build method
Builds the final widget for this display mode for this item. Sub-classes implement this to build the widget that is appropriate for the given display mode.
Implementation
@override
Widget build(BuildContext context, CommandBarItemDisplayMode displayMode) {
assert(debugCheckHasFluentTheme(context));
switch (displayMode) {
case CommandBarItemDisplayMode.inPrimary:
case CommandBarItemDisplayMode.inPrimaryCompact:
final showIcon = icon != null;
final showLabel = label != null &&
(displayMode == CommandBarItemDisplayMode.inPrimary || !showIcon);
return IconButton(
key: key,
onPressed: onPressed,
onLongPress: onLongPress,
focusNode: focusNode,
autofocus: autofocus,
style: ButtonStyle(
backgroundColor: ButtonState.resolveWith((states) {
final theme = FluentTheme.of(context);
return ButtonThemeData.uncheckedInputColor(
theme,
states,
transparentWhenNone: true,
);
}),
),
icon: Row(mainAxisSize: MainAxisSize.min, children: [
if (showIcon)
IconTheme.merge(
data: const IconThemeData(size: 16),
child: icon!,
),
if (showIcon && showLabel) const SizedBox(width: 10),
if (showLabel) label!,
]),
);
case CommandBarItemDisplayMode.inSecondary:
return Padding(
padding: const EdgeInsetsDirectional.only(end: 8.0, start: 8.0),
child: FlyoutListTile(
key: key,
onPressed: onPressed,
focusNode: focusNode,
autofocus: autofocus,
icon: icon,
text: label ?? const SizedBox.shrink(),
),
);
}
}