Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an AppBar with a bottom coloured border in Flutter?

I would like to create an App Bar like this which has a bottom border as well a tint of shadow which can be done using elevation. Could someone provide a sample code snippet to achieve this

AppBar with Border

like image 890
Keshav Aditya R.P Avatar asked Nov 20 '18 12:11

Keshav Aditya R.P


People also ask

How do I add bottom border to AppBar in flutter?

You can use BoxDecoration to add border radius and shadow to a Container/DecoratedBox. You can also create a custom widget using below code snippet. In Flutter, you can have a custom shape in the AppBar Widget with shape property.

How do I change the shape of AppBar flutter?

You can change the shape of the app bar by setting shape property. shape property accept ShapeBorder widget. You can use RoundedRectangleBorder widget to set round rectangle corner widget. Also if you need more shape edge you can use BeveledRectangleBorder widget for that.

How do you style text in AppBar flutter?

Here's how you do it: Step 1: Locate the file where you have placed the AppBar widget. Step 2: Inside the AppBar widget, find the Text widget inside the title parameter. Step 3: Inside the Text widget, add the style parameter and add the TextStyle widget.

What is silver AppBar in flutter?

SliverAppBar is a Material Design widget in flutter which gives scrollable or collapsible app-bar. The word Sliver is given to scrollable areas here. SliverAppBar basically gives us means to create an app-bar that can change appearance, blend in the background, or even disappear as we scroll.


4 Answers

Maybe something like this

AppBar(
   bottom: PreferredSize(
      child: Container(
         color: Colors.orange,
         height: 4.0,
      ),
      preferredSize: Size.fromHeight(4.0)),
   )
like image 160
Andrey Turkovsky Avatar answered Sep 19 '22 01:09

Andrey Turkovsky


You can use the AppBar's shape property to achieve this:

AppBar(
  shape: Border(
    bottom: BorderSide(
      color: Colors.orange,
      width: 4
    )
  ),
  elevation: 4,
  /* ... */
)
like image 36
shennan Avatar answered Sep 17 '22 01:09

shennan


Ideally you should make your own appbar if you want a truly customizable design. Example:

class MyAppbar extends StatelessWidget implements PreferredSizeWidget {
  final Widget title;

  const MyAppbar({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      elevation: 26.0,
      color: Colors.white,
      child: Container(
        padding: const EdgeInsets.all(10.0),
        alignment: Alignment.centerLeft,
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: Colors.deepOrange,
              width: 3.0,
              style: BorderStyle.solid,
            ),
          ),
        ),
        child: title,
      ),
    );
  }

  final Size preferredSize = const Size.fromHeight(kToolbarHeight);
}
like image 25
Rémi Rousselet Avatar answered Sep 17 '22 01:09

Rémi Rousselet


Now a shadowColor Property is available in AppBar which you can use easily like this:

AppBar( shadowColor : Colors.blue )

like image 42
Kishan Somaiya Avatar answered Sep 19 '22 01:09

Kishan Somaiya