Flutter 不´;不要在颤振中刷新旋转滑翔机

Flutter 不´;不要在颤振中刷新旋转滑翔机,flutter,google-cloud-firestore,carousel,Flutter,Google Cloud Firestore,Carousel,我试图制作一个应用程序来显示图像,为此我使用Firestore、Flatter。。。对于滑块,我正在使用插件显示这些图像,但当我从Firestore接收到新图像时,滑块不会显示新图像,但圆圈(指示器)显示新的圆圈,但也不起作用,指示器仅对初始图像起作用 我在旋转木马上的代码: _loadCarrouselFood(){ var carouselSlider = CarouselSlider( viewportFraction: 1.0, aspectRatio:

我试图制作一个应用程序来显示图像,为此我使用Firestore、Flatter。。。对于滑块,我正在使用插件显示这些图像,但当我从Firestore接收到新图像时,滑块不会显示新图像,但圆圈(指示器)显示新的圆圈,但也不起作用,指示器仅对初始图像起作用

我在旋转木马上的代码:

_loadCarrouselFood(){
    var carouselSlider = CarouselSlider(
      viewportFraction: 1.0,
      aspectRatio: 2.0,
      autoPlay: false,
      enlargeCenterPage: true,
      items: child,
      onPageChanged: (index) {
        setState(() {
          _current = index;
        });
        LatLng locationDish = LatLng(_locationDish[_current].latitude, _locationDish[_current].longitude);
          moveCameraTo(locationDish);
      },
    );

    setState(() {
      _sliderDish = carouselSlider;
    });

    return carouselSlider;
  }
}
Firestore功能:

_getInfoDish() async{

    List<LocationDish> _locationDishTmp = <LocationDish>[];
    List<Dish> _dishCardTmp = <Dish>[];
    bool hasFoodInArray = false;

    Firestore.instance // Get the firebase instance
      .collection(Constants.NAME_COLECTION) // Get the informations collection
      .snapshots() // Get the Stream of DocumentSnapshot
      .listen((QuerySnapshot snapshot){

        _locationDishTmp.clear();
        _dishCardTmp.clear();

        print(":::::: - FIRESTORE - ::::::");  

        snapshot.documents.forEach((obj){

        //Set dish to Cards
        _dishCardTmp.add(
          Dish(
            id: obj.data["id"],
            name: obj.data["name"],
            photoURL: 'https://recetaparahoy.com/wp-content/uploads/2017/06/ceviche-peruano-630x420.jpg',
            score: obj.data["score"].toDouble(),
          ),
        );

        });

        if(_locationDishTmp.length > 0)
        {
          setState(() {
            //add only food recent data
            for(int i = 0; i < _locationDishTmp.length; i++){
              _locationDish.add(_locationDishTmp[i]);
              _dishCard.add(_dishCardTmp[i]);
            }

            //_current = _locationDish.length-1;
            _hasFoodOnMap = true;            
          });
        }
      }); 
  }
\u getInfoDish()异步{
列表_locationDishTmp=[];
列表_dishCardTmp=[];
bool hasFoodInArray=false;
Firestore.instance//获取firebase实例
.collection(Constants.NAME\u collection)//获取信息集合
.snapshots()//获取DocumentSnapshot的流
.listen((查询快照快照){
_位置dishtmp.clear();
_dishCardTmp.clear();
打印(“::::-FIRESTORE-:::”;
snapshot.documents.forEach((obj){
//点菜
_dishCardTmp.add(
盘子(
id:obj.data[“id”],
名称:对象数据[“名称”],
photoURL:'https://recetaparahoy.com/wp-content/uploads/2017/06/ceviche-peruano-630x420.jpg',
分数:对象数据[“分数”].toDouble(),
),
);
});
如果(_locationDishTmp.length>0)
{
设置状态(){
//仅添加最新数据
对于(int i=0;i<\u locationDishTmp.length;i++){
_添加(_locationDishTmp[i]);
_添加(_dishCardTmp[i]);
}
//_电流=_locationDish.length-1;
_hasFoodOnMap=true;
});
}
}); 
}

请,有人可以说我的错误,或者任何其他解决方案,我希望我的解释是清楚的,thx很多

您可以在下面复制粘贴运行完整代码
我使用下面的演示来模拟这种情况
当构建项可见时,可以使用
CarouselSlider.builder
build项

工作演示

完整代码

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(        
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 1;
  String url = 'https://picsum.photos/250?image=';
  List<String> urlList = ['https://picsum.photos/250?image=1'];
  int _current = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
      urlList.add('https://picsum.photos/250?image=${_counter}');
    });
  }

  List<T> map<T>(List list, Function handler) {
    List<T> result = [];
    for (var i = 0; i < list.length; i++) {
      result.add(handler(i, list[i]));
    }

    return result;
  }

  @override
  Widget build(BuildContext context) {    
    return Scaffold(
      appBar: AppBar(        
        title: Text(widget.title),
      ),
      body: Center(        
        child: Column(         
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            CarouselSlider.builder(
              autoPlay: false,
              enlargeCenterPage: true,
              aspectRatio: 2.0,
              onPageChanged: (index) {
                setState(() {
                  _current = index;
                });
              },
              itemCount: urlList.length,
              itemBuilder: (BuildContext context, int index) =>
                  Container(
                    child: Image.network(urlList[index]),
                  ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: map<Widget>(
                urlList,
                    (index, url) {
                  return Container(
                    width: 8.0,
                    height: 8.0,
                    margin: EdgeInsets.symmetric(vertical: 10.0, horizontal: 2.0),
                    decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        color: _current == index
                            ? Color.fromRGBO(0, 0, 0, 0.9)
                            : Color.fromRGBO(0, 0, 0, 0.4)),
                  );
                },
              ),
            ),
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), 
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:carousel_slider/carousel_slider.dart”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题资料(
主样本:颜色。蓝色,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
int _计数器=1;
字符串url='0https://picsum.photos/250?image=';
列表urlList=['https://picsum.photos/250?image=1'];
int _电流=0;
void _incrementCounter(){
设置状态(){
_计数器++;
urlist.add('https://picsum.photos/250?image=${u counter}');
});
}
列表映射(列表、函数处理程序){
列表结果=[];
对于(变量i=0;i
容器(
子项:Image.network(urlist[index]),
),
),
划船(
mainAxisAlignment:mainAxisAlignment.center,
儿童:地图(
URL列表,
(索引,url){
返回容器(
宽度:8.0,
身高:8.0,
边缘:边缘组。对称(垂直:10.0,水平:2.0),
装饰:盒子装饰(
形状:BoxShape.circle,
颜色:_当前==索引
?颜色。来自RGBO(0,0,0,0.9)
:Color.fromRGBO(0,0,0,0.4)),
);
},
),
),
正文(
“您已经按了这么多次按钮:”,
),
正文(
“$”计数器“,
风格:Theme.of(context).textTheme.headline4,
),
],
),
),
浮动操作按钮:浮动操作按钮(
按下时:\ u递增计数器,
工具提示:“增量”,
子:图标(Icons.add),
), 
);
}
}

您可以复制粘贴运行下面的完整代码
我使用下面的演示来模拟这种情况
当构建项可见时,可以使用
CarouselSlider.builder
build项

工作演示

完整代码

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(        
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 1;
  String url = 'https://picsum.photos/250?image=';
  List<String> urlList = ['https://picsum.photos/250?image=1'];
  int _current = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
      urlList.add('https://picsum.photos/250?image=${_counter}');
    });
  }

  List<T> map<T>(List list, Function handler) {
    List<T> result = [];
    for (var i = 0; i < list.length; i++) {
      result.add(handler(i, list[i]));
    }

    return result;
  }

  @override
  Widget build(BuildContext context) {    
    return Scaffold(
      appBar: AppBar(        
        title: Text(widget.title),
      ),
      body: Center(        
        child: Column(         
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            CarouselSlider.builder(
              autoPlay: false,
              enlargeCenterPage: true,
              aspectRatio: 2.0,
              onPageChanged: (index) {
                setState(() {
                  _current = index;
                });
              },
              itemCount: urlList.length,
              itemBuilder: (BuildContext context, int index) =>
                  Container(
                    child: Image.network(urlList[index]),
                  ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: map<Widget>(
                urlList,
                    (index, url) {
                  return Container(
                    width: 8.0,
                    height: 8.0,
                    margin: EdgeInsets.symmetric(vertical: 10.0, horizontal: 2.0),
                    decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        color: _current == index
                            ? Color.fromRGBO(0, 0, 0, 0.9)
                            : Color.fromRGBO(0, 0, 0, 0.4)),
                  );
                },
              ),
            ),
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), 
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:carousel_slider/carousel_slider.dart”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题资料(
主样本:颜色。蓝色,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}