I am relatively new in Flutter and I write simple TabBarView like this.
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: ThemeData(
primaryColor: HexColor("#2E58A1"),
),
home: DefaultTabController(
length: 4,
child: new Scaffold(
body: TabBarView(
physics: NeverScrollableScrollPhysics(),
children: [
new Page1(),
new Page2(),
new Page3(),
new Container(
color: Colors.red,
),
],
),
bottomNavigationBar: new TabBar(
tabs: [
Tab(
icon: new Icon(Icons.home),
),
Tab(
icon: new Icon(Icons.rss_feed),
),
Tab(
icon: new Icon(Icons.perm_identity),
),
Tab(icon: new Icon(Icons.settings),)
],
labelColor: HexColor("#2E58A1"),
unselectedLabelColor: HexColor("#CBCCCD"),
indicatorSize: TabBarIndicatorSize.label,
indicatorPadding: EdgeInsets.all(5.0),
indicatorColor: HexColor("#2E58A1"),
),
backgroundColor: Colors.white,
),
),
);
}
In native iOS application, it doesn't overlap tabbar and slider like this.
How shall I re-write my code?
wrap your MaterialApp with SafeArea widget.
or you can just wrap your TabBar with SafeArea
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: ThemeData(),
home: SafeArea(
child: DefaultTabController(
length: 4,
child: new Scaffold(
body: TabBarView(
physics: NeverScrollableScrollPhysics(),
children: [
new Page1(),
new Page2(),
new Page3(),
new Container(
color: Colors.red,
),
],
),
bottomNavigationBar: new TabBar(
tabs: [
Tab(
icon: new Icon(Icons.home),
),
Tab(
icon: new Icon(Icons.rss_feed),
),
Tab(
icon: new Icon(Icons.perm_identity),
),
Tab(
icon: new Icon(Icons.settings),
)
],
labelColor: HexColor("#2E58A1"),
unselectedLabelColor: HexColor("#CBCCCD"),
indicatorSize: TabBarIndicatorSize.label,
indicatorPadding: EdgeInsets.all(5.0),
indicatorColor: HexColor("#2E58A1"),
),
backgroundColor: Colors.white,
),
),
),
);
}
}