我试图发送短信到31003,我的短信内容将是"LS“空间”用户许可证号码“,但在更新我的插件URL_launcher到6.1.3,它显示了一些错误。
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
final Uri _url1 = Uri.parse('sms:31003?body=LC%20');
final textFieldController = TextEditingController();
class SeeSms extends StatelessWidget {
const SeeSms({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GridView.count(
crossAxisCount: 2,
primary: false,
padding: const EdgeInsets.all(20),
crossAxisSpacing: 5,
mainAxisSpacing: 5,
childAspectRatio: 1,
children: <Widget>[
InkWell(
onTap: _launchURL1,
child: Container(
//padding: const EdgeInsets.all(10),
padding: const EdgeInsets.only(top: 20),
decoration: BoxDecoration(
image: const DecorationImage(
image: AssetImage('assets/images/ntc.png'),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(10),
boxShadow: const [
BoxShadow(
color: Color(0x19000000),
blurRadius: 20,
offset: Offset(0, 1),
),
],
),
),
),
],
);
}
_launchURL1() async {
// get license number from user via dialog
String licenseNumber = await Get.defaultDialog(
radius: 3,
titlePadding: const EdgeInsets.only(top: 20, bottom: 20),
contentPadding: const EdgeInsets.only(left: 20, right: 20),
title: 'Enter License Number',
content: TextField(
controller: textFieldController,
autofocus: true,
decoration: const InputDecoration(
hintText: 'Example: 01-01-00012345',
),
),
confirm: Padding(
padding: const EdgeInsets.only(bottom: 20.0, top: 20.0),
child: ElevatedButton(
child: const Text('Send SMS '),
onPressed: () {
Get.back();
launchUrl(_url1 + textFieldController.text);
},
),
),
);
}
}所有这些都很好,但是“参数类型‘'String’不能分配给参数类型'Uri'”来处理这个错误。这个问题正在讨论中。
发布于 2022-06-14 21:50:09
你确定这就是你所犯的错误吗?我宁愿怀疑这一点:
参数类型'dynamic‘不能分配给参数类型'Uri’。
无论哪种方式,从url_launcher版本6.1.0开始,方法launchUrl()都接受一个URI作为参数,而不是一个字符串。因此,您必须将例如_url1作为launchUrl(_url1)传递给方法
此外,如果我没有弄错的话,您就不能简单地在URI和字符串之间使用+操作符,就像在要将它传递给launchUrl()-method时执行_url1 + textFieldController.text时那样。
https://stackoverflow.com/questions/72623210
复制相似问题