Search code examples
dartfluttermaterial-designflutter-sliver

How to make FAB wider


How can I make bottom FAB like below image?

enter image description here

Here is the my current code example:

class _ItemDetailsState extends State<ItemDetails> {
  @override
  Widget build(BuildContext context) {
    double height = MediaQuery.of(context).size.height * 0.42;
    return Scaffold(
        body: Stack(children: <Widget>[
      CustomScrollView(
        slivers: <Widget>[
          ...
        ],
      ),
      Positioned(
          bottom: 0,
          child: FloatingActionButton(
              elevation: 4,
              onPressed: () {},
              child: Text("SAVE THE CHANGES"),
            ),
          ))
    ]));
  }
}

I tried lot but no luck :( Is there any solutions? Thank you for advice :)


Solution

  • It's not possible to set FAB's size. Instead, you must use a RawMaterialButton, copy FAB's default attributes and change the size:

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Stack(
          alignment: Alignment.bottomCenter,
          children: <Widget>[
            CustomScrollView(
              slivers: <Widget>[
                ...
              ],
            ),
            RawMaterialButton(
              elevation: 6,
              highlightElevation: 12.0,
              constraints: BoxConstraints(
                minHeight: 48.0,
                minWidth: double.infinity,
                maxHeight: 48.0,
              ),
              fillColor: Theme.of(context).accentColor,
              textStyle: Theme.of(context).accentTextTheme.button.copyWith(
                color: Theme.of(context).accentIconTheme.color,
                letterSpacing: 1.2,
              ),
              child: Text("SAVE THE CHANGE"),
              onPressed: () {},
            )
          ],
        ),
      );
    }