Created
April 24, 2024 00:16
-
-
Save ricardogottheil/7106270190eea0597ce032983f21399b to your computer and use it in GitHub Desktop.
Ejemplo 1 - Configuración Básica - BottomNavigationBar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(const MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| home: HomeScreen(), | |
| ); | |
| } | |
| } | |
| class HomeScreen extends StatefulWidget { | |
| @override | |
| _HomeScreenState createState() => _HomeScreenState(); | |
| } | |
| class _HomeScreenState extends State<HomeScreen> { | |
| int _selectedIndex = 0; | |
| static const List<Widget> _widgetOptions = <Widget>[ | |
| Text('Inicio'), | |
| Text('Buscar'), | |
| Text('Notificaciones'), | |
| ]; | |
| void _onItemTapped(int index) { | |
| setState(() { | |
| _selectedIndex = index; | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Center( | |
| child: _widgetOptions.elementAt(_selectedIndex), | |
| ), | |
| bottomNavigationBar: BottomNavigationBar( | |
| items: const <BottomNavigationBarItem>[ | |
| BottomNavigationBarItem( | |
| icon: Icon(Icons.home), | |
| label: 'Inicio', | |
| ), | |
| BottomNavigationBarItem( | |
| icon: Icon(Icons.search), | |
| label: 'Buscar', | |
| ), | |
| BottomNavigationBarItem( | |
| icon: Icon(Icons.notifications), | |
| label: 'Notificaciones', | |
| ), | |
| ], | |
| currentIndex: _selectedIndex, | |
| selectedItemColor: Colors.amber[800], | |
| onTap: _onItemTapped, | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment