How can i set HomePage() as my default page after i get into my app ? My app design put the Home Button in the middle of Bottom NavBar.
The Bottom NavBar was fine, it works well and start from the middle, but the page always starts from the CameraPage()
the code looks like this
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.cyan,
),
home: Home(),
);
}
}
This is the Home()
class Home extends StatefulWidget {
Home({Key key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
PageController _pageController = new PageController();
List<Widget> _screens = [
CameraPage(),
HomePage(),
InventoryPage(),
];
int _selectedIndex = 0;
void _onPagedChanged(int index) {
setState(() {
_selectedIndex = index;
});
}
void _onItemTapped(int selectedIndex) {
_pageController.jumpToPage(selectedIndex);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xfff8f5f1),
bottomNavigationBar: CurvedNavigationBar(
index: _selectedIndex,
onTap: _onItemTapped,
items: <Widget>[
ImageIcon(
AssetImage(''),
size: 30,
),
ImageIcon(
AssetImage(''),
size: 30,
),
ImageIcon(
AssetImage(''),
size: 30,
),
],
),
body: PageView(
controller: _pageController,
children: _screens,
onPageChanged: _onPagedChanged,
),
);
}
}