Developments/Flutter

Widget] Material - Bottom Navigation Bar

Meuse 2022. 8. 3. 08:31
반응형

 

Example Code]

import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'BottomNavigationBar',
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.blue,
),
home: const MainPage(),
);
}
}
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
int _currentIndex = 0;
static final List<Widget> _widgetOptions = <Widget>[
const Text('abc View'),
const Text('123 View'),
];
void _onTappedItem(int index) {
setState(() => _currentIndex = index);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Material3 Bottom Navigation Bar'),
),
body: Center(child: _widgetOptions.elementAt(_currentIndex)),
bottomNavigationBar: BottomNavigationBar(
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.abc_outlined),
label: "abc",
),
BottomNavigationBarItem(
icon: Icon(Icons.onetwothree_outlined),
label: "123",
),
],
onTap: _onTappedItem,
currentIndex: _currentIndex,
),
);
}
}

 

Reference]

 

Widget] Cupertino - Tab Bar

Example] Widget] Material - Bottom Navigation Bar Example Code] Reference] BottomNavigationBar class - material library - Dart API A material widget that's displayed at the bottom of an app for sel..

meuse.tistory.com

 

 

BottomNavigationBar class - material library - Dart API

A material widget that's displayed at the bottom of an app for selecting among a small number of views, typically between three and five. The bottom navigation bar consists of multiple items in the form of text labels, icons, or both, laid out on top of a

api.flutter.dev

 

반응형

'Developments > Flutter' 카테고리의 다른 글

Flutter/Widget] Tabbar  (0) 2022.12.02
Flutter/Package] image_picker  (0) 2022.11.16
Flutter/Package] firebase_remote_config  (0) 2022.11.16
Flutter] Localizations  (0) 2022.11.07
Widget] Cupertino - Tab Bar  (0) 2022.08.03