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
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.
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.
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.
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.
Maybe something like this
AppBar(
bottom: PreferredSize(
child: Container(
color: Colors.orange,
height: 4.0,
),
preferredSize: Size.fromHeight(4.0)),
)
You can use the AppBar's shape
property to achieve this:
AppBar(
shape: Border(
bottom: BorderSide(
color: Colors.orange,
width: 4
)
),
elevation: 4,
/* ... */
)
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);
}
Now a shadowColor
Property is available in AppBar which you can use easily like this:
AppBar( shadowColor : Colors.blue )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With