Skip to content

Instantly share code, notes, and snippets.

@anoobbava
Created October 4, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anoobbava/9160d631bc7913182d91bd71854bebdd to your computer and use it in GitHub Desktop.
Save anoobbava/9160d631bc7913182d91bd71854bebdd to your computer and use it in GitHub Desktop.
main.dart for blogging
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