-
-
Save AMT-Cheif/4875599c352836f75bd62139a1ce48d9 to your computer and use it in GitHub Desktop.
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'; | |
| import 'package:flutter/rendering.dart'; | |
| class Destination { | |
| const Destination(this.title, this.icon, this.color); | |
| final String title; | |
| final IconData icon; | |
| final MaterialColor color; | |
| } | |
| const List<Destination> allDestinations = <Destination>[ | |
| Destination('Home', Icons.home, Colors.teal), | |
| Destination('Business', Icons.business, Colors.cyan), | |
| Destination('School', Icons.school, Colors.orange), | |
| Destination('Flight', Icons.flight, Colors.blue) | |
| ]; | |
| class DestinationView extends StatefulWidget { | |
| const DestinationView({ Key key, this.destination }) : super(key: key); | |
| final Destination destination; | |
| @override | |
| _DestinationViewState createState() => _DestinationViewState(); | |
| } | |
| class _DestinationViewState extends State<DestinationView> { | |
| TextEditingController _textController; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| _textController = TextEditingController( | |
| text: 'sample text: ${widget.destination.title}', | |
| ); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text('${widget.destination.title} Text'), | |
| backgroundColor: widget.destination.color, | |
| ), | |
| backgroundColor: widget.destination.color[100], | |
| body: Container( | |
| padding: const EdgeInsets.all(32.0), | |
| alignment: Alignment.center, | |
| child: TextField(controller: _textController), | |
| ), | |
| ); | |
| } | |
| @override | |
| void dispose() { | |
| _textController.dispose(); | |
| super.dispose(); | |
| } | |
| } | |
| class HomePage extends StatefulWidget { | |
| @override | |
| _HomePageState createState() => _HomePageState(); | |
| } | |
| class _HomePageState extends State<HomePage> with TickerProviderStateMixin<HomePage> { | |
| int _currentIndex = 0; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: SafeArea( | |
| top: false, | |
| child: IndexedStack( | |
| index: _currentIndex, | |
| children: allDestinations.map<Widget>((Destination destination) { | |
| return DestinationView(destination: destination); | |
| }).toList(), | |
| ), | |
| ), | |
| bottomNavigationBar: BottomNavigationBar( | |
| currentIndex: _currentIndex, | |
| onTap: (int index) { | |
| setState(() { | |
| _currentIndex = index; | |
| }); | |
| }, | |
| items: allDestinations.map((Destination destination) { | |
| return BottomNavigationBarItem( | |
| icon: Icon(destination.icon), | |
| backgroundColor: destination.color, | |
| title: Text(destination.title) | |
| ); | |
| }).toList(), | |
| ), | |
| ); | |
| } | |
| } | |
| void main() { | |
| runApp(MaterialApp(home: HomePage(), debugShowCheckedModeBanner: false)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment