build method
Override this method to build widgets that depend on the state of the listenable (e.g., the current value of the animation).
Implementation
@override
Widget build(BuildContext context) {
final Animation<double> animation = listenable as Animation<double>;
bool dark = Theme.of(context).brightness == Brightness.dark;
void _performAction([bool isLong = false]) {
if (onTap != null && !isLong) {
onTap!();
} else if (onLongPress != null && isLong) {
onLongPress!();
}
toggleChildren!();
}
Widget buildLabel() {
if (label == null && labelWidget == null) return Container();
if (labelWidget != null) {
return GestureDetector(
onTap: _performAction,
onLongPress: () => _performAction(true),
child: labelWidget,
);
}
return GestureDetector(
onTap: _performAction,
onLongPress: () => _performAction(true),
child: Container(
alignment: labelLocation == LabelLocation.left ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 8.0),
decoration: BoxDecoration(
color: labelBackgroundColor,
borderRadius: const BorderRadius.all(Radius.circular(6.0)),
boxShadow: labelShadow,
),
child: Text(label!, style: labelStyle),
),
),
);
}
Widget button = ScaleTransition(
scale: animation,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: FloatingActionButton(
key: btnKey,
heroTag: heroTag,
onPressed: _performAction,
backgroundColor: backgroundColor ?? Colors.white,
foregroundColor: foregroundColor ?? (dark ? Colors.white : Colors.black),
elevation: elevation ?? 0.0,
child: child,
shape: shapeBorder,
),
));
List<Widget> children = [
if (label != null || labelWidget != null)
Expanded(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 8),
key: (child == null) ? btnKey : null,
child: labelLocation == LabelLocation.left ? buildLabel() : null,
),
),
if (child != null)
Container(
height: buttonSize.height,
width: buttonSize.width,
child: (onLongPress == null)
? button
: FittedBox(
child: GestureDetector(
onLongPress: () => _performAction(true),
child: button,
),
),
),
Expanded(
child: Container(
alignment: Alignment.centerLeft,
child: labelLocation == LabelLocation.right ? buildLabel() : null,
))
];
Widget _buildColumnOrRow(
{CrossAxisAlignment? crossAxisAlignment,
MainAxisAlignment? mainAxisAlignment,
required List<Widget> children,
MainAxisSize? mainAxisSize}) {
return Container(
child: Row(
mainAxisSize: mainAxisSize ?? MainAxisSize.max,
mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.start,
crossAxisAlignment:
crossAxisAlignment ?? CrossAxisAlignment.center,
children: children,
),
);
}
return visible
? Container(
// margin: margin,
child: _buildColumnOrRow(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: children,
),
)
: Container();
}