Advertisement
yudiwbs

flutter_bottom_nav2

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