我尝试在ElevatedButton中启动URL链接,但如果按下按钮,它将不起作用,它不会执行任何操作,是否有其他操作可用于ElevatedButton,或者我是否应该编写其他标签
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/material.dart';
class MyAppThree extends StatefulWidget {
const MyAppThree({super.key});
@override
State<StatefulWidget> createState() => _MyAppThreeState();
}
class _MyAppThreeState extends State<StatefulWidget> {
_launchURL() async {
const url = 'https://www.youtube.com/';
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
throw 'Could not launch $url';
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
title: const Text(''),
),
body: Container(
child: Column(
children: <Widget>[
ElevatedButton(
onPressed: _launchURL,
child: Text(
'TAG Here',
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
const Color.fromARGB(255, 55, 55, 55)),
),
),
1条答案
按热度按时间rggaifut1#
从Android 11(API 30)开始,您必须在Android清单中添加一个元素作为根元素的子元素: