Skip to content

Why Bubble isn't a Widget? #36

@eximius313

Description

@eximius313

FloatingActionBubble accepts only Bubble as items, but Bubble is not a widget (BubbleMenu is) so one can not assign key to it.
Why not make Bubble a StatelessWidget and get rid of BubbleMenu?
I mean:

/// Creates a bubble item for floating action menu button.
class Bubble extends StatelessWidget {
  const Bubble({
    required IconData icon,
    required Color iconColor,
    required String title,
    required TextStyle titleStyle,
    required Color bubbleColor,
    required this.onPress,
    super.key,
  })  : _icon = icon,
        _iconColor = iconColor,
        _title = title,
        _titleStyle = titleStyle,
        _bubbleColor = bubbleColor;

  final IconData _icon;
  final Color _iconColor;
  final String _title;
  final TextStyle _titleStyle;
  final Color _bubbleColor;
  final void Function() onPress;

  @override
  Widget build(BuildContext context) => MaterialButton(
        shape: const StadiumBorder(),
        padding: const EdgeInsets.only(top: 11, bottom: 13, left: 32, right: 32),
        color: _bubbleColor,
        splashColor: Colors.grey.withOpacity(0.1),
        highlightColor: Colors.grey.withOpacity(0.1),
        elevation: 2,
        highlightElevation: 2,
        disabledColor: _bubbleColor,
        onPressed: onPress,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Icon(
              _icon,
              color: _iconColor,
            ),
            const SizedBox(
              width: 10.0,
            ),
            Text(
              _title,
              style: _titleStyle,
            ),
          ],
        ),
      );
}

You just use:

child: items[index],

instead of:

child: BubbleMenu(items[index]),

and it works.
It's simple as that and doesn't break compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions