【发布时间】:2019-12-10 03:50:08
【问题描述】:
我目前有 5 个标签页,如何在启动应用程序时设置默认标签页?假设我希望帐户选项卡成为打开应用程序时的默认选项卡。
我该怎么做?顺便说一句,我使用 WebView 插件来显示网站的内容。
下面是我的 main.dart 文件的代码。我试过搜索,但我发现的所有解决方案都不适合我(我认为我搜索错误的单词。另外,我是新来的)非常感谢!
import 'package:syncshop/widgets/cart_page.dart';
import 'package:syncshop/widgets/categories_page.dart';
import 'package:syncshop/widgets/home_page.dart';
import 'package:syncshop/widgets/profile_account.dart';
import 'package:syncshop/widgets/search_page.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyAppState();
}
}
class MyAppState extends State<MyApp> {
int _selectedPage = 0;
final _pageOptions = [
HomeScreen(),
CategoriesPage(),
SearchPage(),
CartPage(),
ProfileAccount(),
];
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Sync Shop',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: _pageOptions[_selectedPage],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _selectedPage,
onTap: (int index) {
setState((){
_selectedPage = index;
});
},
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("Home"),
),
BottomNavigationBarItem(icon: Icon(Icons.category), title: Text("Categories"),
),
BottomNavigationBarItem(icon: Icon(Icons.search), title: Text("Search"),
),
BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), title: Text("Cart"),
),
BottomNavigationBarItem(icon: Icon(Icons.account_circle), title: Text("Profile"),
),
],
),
),
);
}
}
【问题讨论】:
标签: flutter flutter-layout flutter-dependencies