Вот простой пример, так как вы не поделились достаточным количеством кода, вы можете сравнить свой код с этим.
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Test',
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Color(0xFF048ec8),
indicatorColor: Colors.red,
cursorColor: Colors.red,
),
home: MainScreenWithTab(),
);
}
}
class MainScreenWithTab extends StatefulWidget {
@override
State<StatefulWidget> createState() => MainScreenWithTabState();
}
class MainScreenWithTabState extends State<MainScreenWithTab> {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text('Screen'),
),
body: Column(
children: <Widget>[
TabBar(
tabs: <Widget>[
Tab(
text: 'Left',
),
Tab(
text: 'Right',
)
],
),
Expanded(
child: TabBarView(children: [
RaisedButton(
child: Text('Tap for new screen'),
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => Screen()));
},
),
FlatButton(
child: Text('Push View 2'),
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => Screen()));
},
),
]),
),
],
),
),
);
}
}
class Screen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Screen'),
),
body: Container(
width: double.infinity,
height: double.infinity,
color: Colors.yellow,
child: Center(
child: Text('New Screen'),
),
),
);
}
}