【发布时间】:2020-07-29 01:54:28
【问题描述】:
我已经用颤振实现了以下BottomNavigationBarItem。 onTap 或 onPressed 我希望左侧的第一个图标(案例 0)使用 url_launcher.dart 在默认浏览器中打开一个 URL。
请问我该如何编码?
void _selectTab(int tabItem) {
setState(() {
widget.currentTab = tabItem;
switch (tabItem) {
case 0:
widget.currentPage = ProfileWidget(parentScaffoldKey: widget.scaffoldKey);
break;
case 1:
widget.currentPage = OrdersWidget(parentScaffoldKey: widget.scaffoldKey);
break;
case 2:
widget.currentPage = OrdersHistoryWidget(parentScaffoldKey: widget.scaffoldKey);
break;
}
});
}
items: [
BottomNavigationBarItem(
icon: Icon(Icons.person),
title: new Container(height: 0.0),
),
BottomNavigationBarItem(
title: new Container(height: 5.0),
icon: Container(
width: 42,
height: 42,
decoration: BoxDecoration(
color: Theme.of(context).accentColor,
borderRadius: BorderRadius.all(
Radius.circular(50),
),
boxShadow: [
BoxShadow(
color: Theme.of(context).accentColor.withOpacity(0.4), blurRadius: 40, offset: Offset(0, 15)),
BoxShadow(
color: Theme.of(context).accentColor.withOpacity(0.4), blurRadius: 13, offset: Offset(0, 3))
],
),
child: new Icon(Icons.shopping_basket, color: Theme.of(context).primaryColor),
)),
BottomNavigationBarItem(
icon: new Icon(Icons.history),
title: new Container(height: 0.0),
),
],
在另一个页面上,我在 ListTile 上使用了以下代码,效果很好。
onTap: () async {
const url = 'http://google.com';
if (await canLaunch(url)) {
await launch(url, forceSafariVC: false);
} else {
throw 'Could not launch $url';
}
},
【问题讨论】: