Navigation - Tabs

 Tabs




Source Code


import 'package:flutter/material.dart';


void main() {
runApp( MaterialApp(
title:" Tabs ",
home:Scaffold(appBar: AppBar(title: Text(' Tabs ',),),
body: Material(
child: Center(
child:
TabsExample()
,
),
) ,
),
));
}






class TabsExample extends StatelessWidget {
const TabsExample({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final _kTabPages = <Widget>[
const Center(child: Icon(Icons.cloud, size: 64.0, color: Colors.teal)),
const Center(child: Icon(Icons.alarm, size: 64.0, color: Colors.cyan)),
const Center(child: Icon(Icons.forum, size: 64.0, color: Colors.blue)),
];
final _kTabs = <Tab>[
const Tab(icon: Icon(Icons.cloud), text: 'Tab1'),
const Tab(icon: Icon(Icons.alarm), text: 'Tab2'),
const Tab(icon: Icon(Icons.forum), text: 'Tab3'),
];
return DefaultTabController(
length: _kTabs.length,
child: Scaffold(
appBar: AppBar(
title: const Text('appbar title'),
backgroundColor: Colors.cyan,
// If `TabController controller` is not provided, then a
// DefaultTabController ancestor must be provided instead.
// Another way is to use a self-defined controller, c.f. "Bottom tab
// bar" example.
bottom: TabBar(
tabs: _kTabs,
),
),
body: TabBarView(
children: _kTabPages,
),
),
);
}
}


Comments