Navigation - BottomNavigationBar
BottomNavigationBar
Source Code
import 'package:flutter/material.dart';
void main() {
runApp( MaterialApp(
title:" BottomNavigationBar ",
home:Scaffold(appBar: AppBar(title: Text(' BottomNavigationBar ',),),
body: Material(
child: Center(
child:
BottomNavigationBarExample()
,
),
) ,
),
));
}
class BottomNavigationBarExample extends StatefulWidget {
const BottomNavigationBarExample({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _BottomNavigationBarExampleState();
}
class _BottomNavigationBarExampleState
extends State<BottomNavigationBarExample> {
int _currentTabIndex = 0;
@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 _kBottmonNavBarItems = <BottomNavigationBarItem>[
const BottomNavigationBarItem(icon: Icon(Icons.cloud), label: 'Tab1'),
const BottomNavigationBarItem(icon: Icon(Icons.alarm), label: 'Tab2'),
const BottomNavigationBarItem(icon: Icon(Icons.forum), label: 'Tab3'),
];
assert(_kTabPages.length == _kBottmonNavBarItems.length);
final bottomNavBar = BottomNavigationBar(
items: _kBottmonNavBarItems,
currentIndex: _currentTabIndex,
type: BottomNavigationBarType.fixed,
onTap: (int index) {
setState(() {
_currentTabIndex = index;
});
},
);
return Scaffold(
body: _kTabPages[_currentTabIndex],
bottomNavigationBar: bottomNavBar,
);
}
}
Comments
Post a Comment