如何在flutter应用程序中使用streambuilder中的链接导航



我试图在flutter应用程序中使用链接,链接是我现在可以使用const链接,但问题是我想使用streambuilder中的链接,那么如何更改我的方法?以下是我尝试的方法


@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
try {
return Scaffold(
body: StreamBuilder(
stream: mystreamofallvideos,
builder: (context, snapshot) {
if (snapshot.hasData &&
snapshot.connectionState != ConnectionState.waiting) {
return PageView.builder(
onPageChanged: (page) {
if (israting = true) {
setState(() {
israting = false;
});
}
},
itemCount: snapshot.data.docs.length,
controller: PageController(
initialPage: widget.currentvideoindex,
viewportFraction: 1),
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
DocumentSnapshot videos = snapshot.data.docs[index];
idovvideo = videos.data()['id'];
return Stack(children: [
- - - - -- - 
InkWell(
onTap: () async {
const url =
videos.data()['productlink'];
if (await canLaunch(url))
await launch(url);
else
throw "Could not launch $url";
},

只是为了澄清这个问题已经得到了回答。

问题是:

const url = videos.data....

解决方案:

final String url = videos.data....

https://dart.dev/guides/language/language-tour#final-和const

最新更新