进入我的应用程序后,如何将 HomePage() 设置为我的默认页面?我的应用程序设计将主页按钮放在底部导航栏的中间。
底部导航栏很好,效果很好,从中间开始,但页面总是从 CameraPage()
代码看起来像这样
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(),
);
}
}
这是 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,
),
);
}
}