Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 如何使用URL_启动程序包从CloudFireStore添加URL_Firebase_Flutter_Dart - Fatal编程技术网

Firebase 如何使用URL_启动程序包从CloudFireStore添加URL

Firebase 如何使用URL_启动程序包从CloudFireStore添加URL,firebase,flutter,dart,Firebase,Flutter,Dart,我正在使用CloudFireStore在Flatter中创建一个卡片布局。该卡包含一个图像、两个图标按钮和一些文本。我希望图标按钮打开我在Firebase中作为字符串添加的URL链接。如何使用url_启动程序包实现这一点?我尝试替换consturl='example.com'在\u launchURL函数中,使用const url=record.url但哥特为record抛出了一个未定义的错误 我对开发和Stackoverflow非常陌生,因此如果我能更好地组织问题,请让我知道。谢谢

我正在使用CloudFireStore在Flatter中创建一个卡片布局。该卡包含一个图像、两个图标按钮和一些文本。我希望图标按钮打开我在Firebase中作为字符串添加的URL链接。如何使用url_启动程序包实现这一点?我尝试替换
consturl='example.com'
\u launchURL
函数中,使用
const url=record.url
但哥特为
record
抛出了一个未定义的错误

我对开发和Stackoverflow非常陌生,因此如果我能更好地组织问题,请让我知道。谢谢

          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              IconButton(
                icon: Icon(FontAwesomeIcons.youtube),
                onPressed: _launchURL(),
              ),
              IconButton(
                icon: Icon(FontAwesomeIcons.google),
                onPressed: _launchURL(),
              ),
            ],
          ),
          Container(
            child: Text(record.gameParagraph),
          ),
        ],
        ),

_launchURL() async {
  const url = 'example.com'; // URL to be added from Cloud Firestore
  if (await canLaunch(url)){
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

class Record {
  final String gameParagraph;
  final String url;
  final DocumentReference reference;

  Record.fromMap(Map<String, dynamic> map, {this.reference})
  : assert(map['gameParagraph'] != null),
    assert(map['url'] != null),
  gameParagraph = map['gameParagraph'],
  url = map['url'];

  Record.fromSnapshot(DocumentSnapshot snapshot)
  : this.fromMap(snapshot.data, reference: snapshot.reference);

  @override
  String toString() => "Record<$gameParagraph:$url>";

}

行(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
图标按钮(
图标:图标(FontAwesomeIcons.youtube),
onPressed:_launchURL(),
),
图标按钮(
图标:图标(FontAwesomeIcons.google),
onPressed:_launchURL(),
),
],
),
容器(
子项:文本(记录.游戏段落),
),
],
),
_启动URL()异步{
const url='example.com';//要从Cloud Firestore添加的url
如果(等待canLaunch(url)){
等待发射(url);
}否则{
抛出“无法启动$url”;
}
}
课堂记录{
最后一段;
最终字符串url;
最终文件参考;
Record.fromMap(映射映射,{this.reference})
:assert(map['gameparation']!=null),
断言(map['url']!=null),
game段落=映射['game段落'],
url=map['url'];
Record.fromSnapshot(文档快照快照)
:this.fromMap(snapshot.data,reference:snapshot.reference);
@凌驾
字符串toString()=>“记录”;
}

您可以添加make
\u launchURL()
以获取字符串值,该值将作为您的url
\u launchURL(字符串url)
,然后

 _launchURL(String url) async {

  if (await canLaunch(url)){
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}
//
 IconButton(
         icon: Icon(FontAwesomeIcons.google),
          onPressed: (){    
              _launchURL(url:record.url),// or _launchURL(record.url)}
          ),