Advertisement
yudiwibisono

flutter_bottomnav

Apr 4th, 2022
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.08 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(const MyApp());
  5. }
  6.  
  7. class MyApp extends StatefulWidget {
  8.   const MyApp({Key? key}) : super(key: key);
  9.   @override
  10.   MyAppState createState() {
  11.     return MyAppState();
  12.   }
  13. }
  14.  
  15. class MyAppState extends State<MyApp> {
  16.   int idx = 0; //index yang aktif
  17.  
  18.   static const List<Center> halaman = [
  19.     Center(child: Text("satu")),
  20.     Center(child: Text("dua"))
  21.   ];
  22.  
  23.   void onItemTap(int index) {
  24.     setState(() {
  25.       idx = index;
  26.     });
  27.   }
  28.  
  29.   @override
  30.   Widget build(BuildContext context) {
  31.     return MaterialApp(
  32.         home: Scaffold(
  33.       appBar: AppBar(title: const Text("Bottom Nav")),
  34.       body: halaman[idx],
  35.       bottomNavigationBar: BottomNavigationBar(
  36.           currentIndex: idx,
  37.           selectedItemColor: Colors.red,
  38.           onTap: onItemTap,
  39.           items: const <BottomNavigationBarItem>[
  40.             BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
  41.             BottomNavigationBarItem(icon: Icon(Icons.school), label: " School"),
  42.           ]),
  43.     ));
  44.   }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement