This example shows how to use a TabBar
for navigating between different sections of an app.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'TabBar Example',
theme: ThemeData(primarySwatch: Colors.blue),
home: TabBarExample(),
);
}
}
class TabBarExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: Text('TabBar Example'),
bottom: TabBar(
tabs: [
Tab(text: 'Home'),
Tab(text: 'Search'),
Tab(text: 'Profile'),
],
),
),
body: TabBarView(
children: [
Center(child: Text('Home Screen')),
Center(child: Text('Search Screen')),
Center(child: Text('Profile Screen')),
],
),
),
);
}
}
Leave a Reply