<aside> 💡 교재 10장 내용 간략하게 줄여서 강의하기
</aside>
예제
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int index = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: index,
children: [
Center(child: Text("0 page")),
Center(child: Text("1 page")),
Center(child: Text("2 page")),
],
),
bottomNavigationBar: BottomNavigationBar(
onTap: (value) {
index = value;
setState(() {});
},
currentIndex: index, // 색칠용도
showSelectedLabels: false,
showUnselectedLabels: false,
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.camera_alt), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.person), label: ""),
],
),
);
}
}
tip 상태관리를 배우고 나면 아래 내용 알려주기