在 Flutter 的 TextFormField 中,用户输入 url 或网站 link 以将其保存到 firebase 数据库,并且应该使用浏览器打开 link
In a TextFormField in flutter user enters a url or website link to save it to firebase database and the link should be opened with browser
在颤动的 TextFormField 中,我想输入一个 url 或网站 link 以将其保存到 firebase 数据库并且 link 应该用浏览器打开,即它应该是保存之前可点击并将其保存到 firebase 数据库。
他应该打开网站或 link 使用 borwser 等
如何在flutter中实现这个功能
我用过url_launcher: plugin和import import 'package:url_launcher/url_launcher.dart';
我的代码如下
child: TextFormField(
validator: (value){
if(value.isEmpty){
return "Please write the Company Website of production";
}else {
website = value;
}
},
keyboardType: TextInputType.name,
autofocus: false,
// controller: _controller,
decoration: InputDecoration(
labelText: ' Company Website ',
hintText: 'Enter the Company Website',
prefixIcon: IconButton(
onPressed: () async {
if (await canLaunch("url")) {
await launch("url");
}
},
icon: Icon(Icons.open_in_browser),
),
),
maxLength: 15,
)
请指导我解决这个问题。
您可以尝试使用以下代码,这会对您有所帮助
TextFormField(
keyboardType: TextInputType.name,
autofocus: false,
controller: textEditingController,
decoration: InputDecoration(
labelText: ' Company Website ',
hintText: 'Enter the Company Website',
prefixIcon: IconButton(
onPressed: () async {
if(textEditingController.text.toString() == null || textEditingController.text.toString() == ""){
print("null data");
}else{
print(textEditingController.text.toString());
if (await canLaunch("https://" + textEditingController.text.toString())) {
await launch("https://" + textEditingController.text.toString());
} else {
throw 'Could not launch ${textEditingController.text.toString()}';
}
}
},
icon: Icon(Icons.open_in_browser),
),
),
maxLength: 15,
),,
在颤动的 TextFormField 中,我想输入一个 url 或网站 link 以将其保存到 firebase 数据库并且 link 应该用浏览器打开,即它应该是保存之前可点击并将其保存到 firebase 数据库。
他应该打开网站或 link 使用 borwser 等
如何在flutter中实现这个功能
我用过url_launcher: plugin和import import 'package:url_launcher/url_launcher.dart';
我的代码如下
child: TextFormField(
validator: (value){
if(value.isEmpty){
return "Please write the Company Website of production";
}else {
website = value;
}
},
keyboardType: TextInputType.name,
autofocus: false,
// controller: _controller,
decoration: InputDecoration(
labelText: ' Company Website ',
hintText: 'Enter the Company Website',
prefixIcon: IconButton(
onPressed: () async {
if (await canLaunch("url")) {
await launch("url");
}
},
icon: Icon(Icons.open_in_browser),
),
),
maxLength: 15,
)
请指导我解决这个问题。
您可以尝试使用以下代码,这会对您有所帮助
TextFormField(
keyboardType: TextInputType.name,
autofocus: false,
controller: textEditingController,
decoration: InputDecoration(
labelText: ' Company Website ',
hintText: 'Enter the Company Website',
prefixIcon: IconButton(
onPressed: () async {
if(textEditingController.text.toString() == null || textEditingController.text.toString() == ""){
print("null data");
}else{
print(textEditingController.text.toString());
if (await canLaunch("https://" + textEditingController.text.toString())) {
await launch("https://" + textEditingController.text.toString());
} else {
throw 'Could not launch ${textEditingController.text.toString()}';
}
}
},
icon: Icon(Icons.open_in_browser),
),
),
maxLength: 15,
),,