Flutter 如何使用firestore图像和Flatter中的onclick启动url创建旋转木马滑块?

Flutter 如何使用firestore图像和Flatter中的onclick启动url创建旋转木马滑块?,flutter,google-cloud-firestore,slider,carousel,Flutter,Google Cloud Firestore,Slider,Carousel,我想用CloudFireStore在Flatter中创建旋转木马滑块。我创建了名为“slider”的CloudFireStore集合,我有两个字段,一个是“image”,另一个是“url” 现在,我需要在旋转木马滑块中对firestore集合进行流式处理,当用户单击图像时,需要启动url 我的旋转木马滑块代码 import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart';

我想用CloudFireStore在Flatter中创建旋转木马滑块。我创建了名为“slider”的CloudFireStore集合,我有两个字段,一个是“image”,另一个是“url”

现在,我需要在旋转木马滑块中对firestore集合进行流式处理,当用户单击图像时,需要启动url

我的旋转木马滑块代码

import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';

class Dashboard extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        SizedBox(height: 15.0),
        CarouselSlider(
          options: CarouselOptions(
              height: 400.0,
              enlargeCenterPage: true,
              autoPlay: true,
              aspectRatio: 16 / 9,
              autoPlayCurve: Curves.fastOutSlowIn,
              enableInfiniteScroll: true,
              autoPlayAnimationDuration: Duration(milliseconds: 800),
              viewportFraction: 0.8),
          items: [
            Container(
              margin: EdgeInsets.all(5.0),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10.0),
                image: DecorationImage(
                  image: AssetImage('$show Firestore image'),
                  onPressed: () {
              launchURL(
                  "$ launch firestore url");
            }
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ],
        ),
      ],
    );
  }
} 
import'package:carousel_slider/carousel_slider.dart';
进口“包装:颤振/材料.省道”;
类Dashboard扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回列表视图(
儿童:[
尺寸箱(高度:15.0),
旋转滑翔机(
选项:旋转木马(
高度:400.0,
放大中心页:正确,
自动播放:对,
专题:16/9,
自动播放曲线:Curves.FastOutSwowin,
启用无限滚动:正确,
autoPlayAnimationDuration:持续时间(毫秒:800),
视口分数:0.8),
项目:[
容器(
边距:所有边缘集(5.0),
装饰:盒子装饰(
边界半径:边界半径。圆形(10.0),
图像:装饰图像(
图像:AssetImage(“$show Firestore image”),
已按下:(){
启动URL(
“$launch firestore url”);
}
适合:BoxFit.cover,
),
),
),
],
),
],
);
}
} 

有人能为我指点迷津吗?

您可以使用FutureBuilder获取文档快照,完成后,您可以将URL存储在列表中,并将列表用于旋转木马

使用FutureBuilder获取URL列表的示例代码:

Future getCarouselWidget() async {
    var firestore = Firestore.instance;
    QuerySnapshot qn = await firestore.collection("carousel").getDocuments();
    return qn.documents;
  }

Widget build(BuildContext context) {
    var idx = 1;
    return Container(
      child: FutureBuilder(
          future: getCarouselWidget(),
          builder: (context, AsyncSnapshot snapshot) {
            List<NetworkImage> list = new List<NetworkImage>();
            if (snapshot.connectionState == ConnectionState.waiting) {
              return new CircularProgressIndicator(); 
            } else {
              if (snapshot.hasError) {
                return new Text("fetch error");
              } else {

                //Create for loop and store the urls in the list 
                for(int i = 0; i < snapshot.data[0].data.length; i++ ) {
                  debugPrint("Index is " + idx.toString());
                  list.add(NetworkImage(snapshot.data[0].data["img_"+idx.toString()]));
                  idx++;
                }
                return new Container(
                    height: 250.0,
                    child: new Carousel(
                      boxFit: BoxFit.cover,
                      images: list,   <== Set the list here 
                      autoplay: true,
                      dotSize: 4.0,
                      indicatorBgPadding: 4.0,
                      animationCurve: Curves.fastOutSlowIn,
                      animationDuration: Duration(milliseconds: 1000),
                    ));
              }
            }
          }),
    );
Future getCarouselWidget()异步{
var firestore=firestore.instance;
QuerySnapshot qn=wait firestore.collection(“carousel”).getDocuments();
返回qn文件;
}
小部件构建(构建上下文){
var-idx=1;
返回容器(
孩子:未来建设者(
future:getCarouselWidget(),
生成器:(上下文,异步快照){
列表=新列表();
if(snapshot.connectionState==connectionState.waiting){
返回新的循环ProgressIndicator();
}否则{
if(snapshot.hasError){
返回新文本(“获取错误”);
}否则{
//创建for循环并将URL存储在列表中
对于(int i=0;i图像:列表,谢谢,但当用户单击旋转木马滑块图像时,我需要打开url(如),我需要从Firestore获取该url。如何操作?这解释了onTap功能,下次您只需从文档快照生成该列表,请确保将其添加到问题陈述中