user9047282
user9047282

Reputation:

Flutter - AppBar Bottom widget

I wanted to ask, because I get a lot of errors, if it is possible to place a Divider() widget like this:

AppBar(
  bottom: Divider()
)

And if yes, could anyone show me how it's possible to do that

Upvotes: 7

Views: 9569

Answers (3)

Sapar Friday
Sapar Friday

Reputation: 66

Yes, you can add Divider() to AppBar bottom.

bottom: const PreferredSize(
  preferredSize: Size.fromHeight(1),
  child: Divider(height: 1),
)

Upvotes: 4

Gaurav Raj
Gaurav Raj

Reputation: 131

try this...

bottom: PreferredSize(
      child: Container(
         color: Colors.orange,
         height: 4.0,
      ),
      preferredSize: Size.fromHeight(4.0)),

Upvotes: 12

chemamolins
chemamolins

Reputation: 20558

If you read the bottom documentation, it must implement PreferredSizeWidget and Divider does not implement it.

But you can create your own version and use it there.

class MyDivider extends Divider implements PreferredSizeWidget {
  MyDivider({
    Key key,
    height = 16.0,
    indent = 0.0,
    color,
  })  : assert(height >= 0.0),
        super(
          key: key,
          height: height,
          indent: indent,
          color: color,
        ) {
    preferredSize = Size(double.infinity, height);
  }

  @override
  Size preferredSize;
}

Upvotes: 4

Related Questions