Read me
๐ฌ IndexStack๊ณผ BottomNavigationBar๋ฅผ ์ฌ์ฉํ ๋ค๋น๊ฒ์ด์ ๋ฐ ์ฑ ๊ตฌ์กฐ ๋ง๋ค๊ธฐ
Code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class MainScreens extends StatefulWidget {
@override
_MainScreensState createState() => _MainScreensState();
}
class _MainScreensState extends State<MainScreens> {
// ์ฌ์ฉ์๊ฐ ํ๋จ ์์ด์ฝ ๋ฒํผ์ ๋๋ ์ ๋ ์์ ฏ์ index ๊ฐ์ ์ ์ฅํ๋ ๋ณ์
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack( // ํ ๋ฒ์ ํ์ ํญ๋ชฉ ํ๋๋ง์ ๋ณด์ฌ์ฃผ๋ ์คํ ์์ ฏ
index: _selectedIndex,
children: [
// ๋ค๋น๊ฒ์ด์
๋ฐ ๋ฒํผ ํด๋ฆญ ์ ๋์ํ๋ ํ๋ฉด ์์ ฏ
HomeScreen(),
NeighborhoodLifeScreen(),
NearMeScreen(),
ChattingScreen(),
MyCarrotScreen()
],
),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.white,
// 3๊ฐ ์ด์์ ์์ดํ
์ ํ์ํ ๋ ์ค์
type: BottomNavigationBarType.fixed,
currentIndex: _selectedIndex,
onTap: (index) {
setState(() {
// ํ๋ฉด์ ๊ฐฑ์ ํ์ฌ ๋ค๋น๊ฒ์ด์
๋ฐ index๋ฅผ IndexStack์ ๋๊ฒจ์ค
_selectedIndex = index;
});
},
items: [
const BottomNavigationBarItem(
label: 'ํ', icon: Icon(CupertinoIcons.home)),
const BottomNavigationBarItem(
label: '๋๋ค์ํ', icon: Icon(CupertinoIcons.square_on_square)),
const BottomNavigationBarItem(
label: '๋ด ๊ทผ์ฒ', icon: Icon(CupertinoIcons.placemark)),
const BottomNavigationBarItem(
label: '์ฑํ
', icon: Icon(CupertinoIcons.chat_bubble_2)),
const BottomNavigationBarItem(
label: '๋์ ๋น๊ทผ', icon: Icon(CupertinoIcons.person)),
],
),
);
}
}
'Flutter > Concept' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ Flutter ] ํ๋ซํผ ๋์ (0) | 2022.02.24 |
---|---|
[ Flutter ] ์ด๋ฏธ์ง (0) | 2022.02.22 |
[ Flutter ] HTTP ํต์ (0) | 2022.01.28 |
[ Flutter ] Web ๋ฐฐํฌ using GitHub (0) | 2022.01.07 |
[ Flutter ] ํ๋ฉด ์ด๋ (0) | 2021.12.29 |