[Flutter] BottomNavigationBar
2020. 12. 26. 19:47ㆍFlutter Mobile App/Flutter 기초
반응형
BottomNavigationBar : 하단부분에 위치한 네비게이션
첫 로딩 시 또는 홈 아이콘 클릭 시
main.dart
더보기
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
static const String _title = '플러더 코드 샘플';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
// theme: ThemeData(
// primarySwatch: Colors.blue,
// visualDensity: VisualDensity.adaptivePlatformDensity,
// ),
//home: MyHomePage(),
home: MyStatefulWidget(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _selectedIdx = 0;
static const TextStyle optionStyle =
TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold
);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'인덱스 0: 홈',
style: optionStyle
),
Text(
'인덱스 1: 비즈니스',
style: optionStyle
),
Text(
'인덱스 2: 학교',
style: optionStyle
)
];
void _onItemTapped(int idx) {
setState(() {
_selectedIdx = idx;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BottomNavigation'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIdx),
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('홈'),
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
title: Text('비즈니스'),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: Text('학교'),
),
],
currentIndex: _selectedIdx,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
);
}
}
반응형
'Flutter Mobile App > Flutter 기초' 카테고리의 다른 글
[Flutter] CircularProgressIndicator (0) | 2020.12.26 |
---|---|
[Flutter] TabBar / TabBarview (0) | 2020.12.26 |
[Flutter] Layout (0) | 2020.12.26 |
[Flutter] Stack (0) | 2020.12.26 |
[Flutter] MediaQuery (0) | 2020.12.26 |