To apply a box shadow to a TabBar
in Flutter, you can wrap it in a Container
and use the BoxDecoration
property. Here's an example:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: Text('TabBar with Shadow'),
bottom: TabBar(
tabs: [
Tab(text: 'Tab 1'),
Tab(text: 'Tab 2'),
Tab(text: 'Tab 3'),
],
),
),
body: TabBarView(
children: [
Container(color: Colors.red),
Container(color: Colors.green),
Container(color: Colors.blue),
],
),
),
);
}
}
If you want to add a shadow effect to the TabBar
, you can wrap the TabBar
in a Container
and apply the BoxDecoration
:
Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
child: TabBar(
tabs: [
Tab(text: 'Tab 1'),
Tab(text: 'Tab 2'),
Tab(text: 'Tab 3'),
],
),
),
In this example, the BoxShadow
is used to create a shadow effect for the TabBar
. You can customize the color, spread radius, blur radius, and offset to achieve the desired shadow appearance.
Remember to adjust the shadow properties to match your design requirements.
Please note that applying a shadow might not work if your AppBar
is already using elevation. In such cases, you might need to use custom widgets or adjust the design to accommodate both effects.