【发布时间】:2021-09-17 03:32:53
【问题描述】:
我正在尝试制作一个颤动的按钮以在应用程序内打开一个 URL 并在 5 秒后将其关闭,然后返回应用程序。
const url = 'https://pub.dev/packages/url_launcher';
floatingActionButton: FloatingActionButton(
onPressed: () {
_launchInBrowser(url);
Timer(const Duration(seconds: 5), () {
closeWebView();
});
},
child: Icon(Icons.add),
backgroundColor: Colors.grey[850],
),
这是在应用内打开 URL 的函数:
Future<void> _launchInBrowser(String url) async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: false,
headers: <String, String>{'header_key': 'header_value'},
);
} else {
throw 'Could not launch $url';
}
}
URL 可以正常打开,但是 5 秒后它没有关闭。我应该使用什么功能来做到这一点? 谢谢!
【问题讨论】:
标签: android flutter flutter-layout flutter-web