main.dart for blogging
This file contains 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_dotenv/flutter_dotenv.dart'; | |
import './pages/home_page.dart'; | |
import './pages/search_movies.dart'; | |
Future main() async { | |
await DotEnv().load('.env'); | |
runApp(MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> with AutomaticKeepAliveClientMixin { | |
int _selectedIndex = 0; | |
final List<Widget> _childWidgets = [MyHomePage(), SearchMovies()]; | |
_onItemTapped(int index) { | |
setState(() { | |
this._selectedIndex = index; | |
}); | |
} | |
@override | |
bool get wantKeepAlive => true; | |
@override | |
Widget build(BuildContext context) { | |
super.build(context); | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primaryColor: Colors.pink[200], | |
), | |
home: Scaffold( | |
body: _childWidgets[_selectedIndex], | |
bottomNavigationBar: BottomNavigationBar( | |
type: BottomNavigationBarType.fixed, | |
items: <BottomNavigationBarItem>[ | |
BottomNavigationBarItem( | |
icon: Icon(Icons.home), | |
title: Text('Home'), | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.search), | |
title: Text('Search'), | |
), | |
], | |
selectedItemColor: Colors.pink[200], | |
currentIndex: _selectedIndex, | |
onTap: _onItemTapped, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment