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
Dart 在我的listview中刷新数据_Dart_Flutter - Fatal编程技术网

Dart 在我的listview中刷新数据

Dart 在我的listview中刷新数据,dart,flutter,Dart,Flutter,更新 这是StreamBuilder代码: 我正在尝试用一个运行Stream.fromFuture的计时器更新数据,但是闪烁和滚动很奇怪 new StreamBuilder( initialData: myInitialData, stream: msgstream, builder: (BuildContext context, AsyncSnapshot<List<Map>>

更新 这是StreamBuilder代码: 我正在尝试用一个运行Stream.fromFuture的计时器更新数据,但是闪烁和滚动很奇怪

new StreamBuilder(
                initialData: myInitialData,
                stream: msgstream,
                builder: (BuildContext context, AsyncSnapshot<List<Map>> snapshot) {
                  switch (snapshot.connectionState) {
                    case ConnectionState.none:
                      return new Text('Waiting to start');
                    case ConnectionState.waiting:
                      return new Text('');
                    default:
                      if (snapshot.hasError) {
                        return new Text('Error: ${snapshot.error}');
                      } else {
                        myInitialData = snapshot.data;
                        return new RefreshIndicator(
                            child: new ListView.builder(
                              itemBuilder: (context, index) {
                                Stream<List<Map>> msgstream2;
                                Future<List<Map>> _responseDate = ChatDB.instance.getMessagesByDate(snapshot.data[index]['msgkey'], snapshot.data[index]['msgdate']);
                                msgstream2 = new Stream.fromFuture(_responseDate);
                                return new StreamBuilder(
                                  initialData: myInitialData2,
                                  stream: msgstream2,
                                  builder: (BuildContext context, AsyncSnapshot<List<Map>> snapshot) {
                                    switch (snapshot.connectionState) {
                                      case ConnectionState.none:
                                        return new Text('Waiting to start');
                                      case ConnectionState.waiting:
                                        return new Text('');
                                      default:
                                        List messList;
                                        var mybytes;
                                        File myimageview;
                                        Image newimageview;
                                        String imgStr;
                                        String vidStr;
                                        String vidimgstr;
                                        myInitialData2 = snapshot.data;
                                        List<dynamic> json = snapshot.data;
                                        List messagelist = [];
                                        json.forEach((element) {

                                          DateTime submitdate =
                                          DateTime.parse(element['submitdate']).toLocal();
                                          String myvideo = (element['chatvideo']);
                                          String myimage = element['chatimage'];
                                          String myvideoimage = element['chatvideoimage'];
                                          File imgfile;
                                          File vidfile;
                                          File vidimgfile;
                                          bool vidInit = false;
                                          Future<Null> _launched;
                                          String localAssetPath;
                                          String localVideoPath;
                                          String mymessage = element['message'].replaceAll("[\u2018\u2019]", "'");
                                          //print('MYDATE: '+submitdate.toString());
                                          _checkFile(File file) async {
                                            var checkfile = await file.exists();
                                            print('VIDEXISTS: '+checkfile.toString());
                                          }
                                          Future<Null> _launchVideo(String url, bool isLocal) async {
                                            if (await canLaunchVideo(url, isLocal)) {
                                              await launchVideo(url, isLocal);
                                            } else {
                                              throw 'Could not launch $url';
                                            }
                                          }
                                          void _launchLocal() =>
                                              setState(() => _launched = _launchVideo(localVideoPath, true)
                                              );

                                          Widget _showVideo() {
                                            return new Flexible(
                                                child: new Card(
                                                  child: new Column(
                                                    children: <Widget>[
                                                      new ListTile(subtitle: new Text('Video'), title: new Text(element['referralname']),),
                                                      new GestureDetector(
                                                        onTap: _launchLocal,
                                                        child: new Image.file(
                                                          vidimgfile,
                                                          width: 150.0,
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                )
                                            );
                                          }

                                          if (myimage != "") {
                                            imgStr = element['chatimage'];
                                            imgfile = new File(imgStr);
                                          }
                                          if (myvideo != "") {
                                            vidStr = element['chatvideo'];
                                            vidimgstr = element['chatvideoimage'];
                                            vidimgfile = new File(vidimgstr);

                                            localVideoPath = '$vidStr';


                                          }

                                          _showLgPic() {
                                            Route route = new MaterialPageRoute(
                                              settings: new RouteSettings(name: "/ShowPic"),
                                              builder: (BuildContext context) => new ShowPic(
                                                image: imgfile,
                                              ),
                                            );
                                            Navigator.of(context).push(route);
                                          }

                                          Widget _showGraphic() {
                                            Widget mywidget;
                                            if (myimage != "") {
                                              mywidget = new GestureDetector(
                                                child: new Image.file(
                                                  imgfile,
                                                  width: 300.0,
                                                ),
                                                onTap: _showLgPic,
                                              );
                                            } else if (myvideo != "") {
                                              mywidget = _showVideo();
                                            } else {
                                              mywidget = new Container();
                                            }
                                            return mywidget;
                                          }

                                          messagelist.add(
                                            new Container(
                                              //width: 300.0,
                                              padding: new EdgeInsets.all(10.0),
                                              child: new Column(
                                                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                                                crossAxisAlignment: CrossAxisAlignment.stretch,
                                                mainAxisSize: MainAxisSize.min,
                                                children: <Widget>[
                                                  new Container(
                                                    padding: new EdgeInsets.only(bottom: 5.0),
                                                    child: new Row(
                                                      mainAxisSize: MainAxisSize.min,
                                                      children: <Widget>[
                                                        new CircleAvatar(
                                                          child: new Text(
                                                            element['sendname'][0],
                                                            style: new TextStyle(fontSize: 15.0),
                                                          ),
                                                          radius: 12.0,
                                                        ),
                                                        new Text('    '),
                                                        new Text(
                                                          element['sendname'],
                                                          style: new TextStyle(
                                                              fontSize: 15.0,
                                                              fontWeight: FontWeight.bold),
                                                        ),
                                                        new Text('    '),
                                                        new Text(
                                                          new DateFormat.Hm().format(submitdate),
                                                          style: new TextStyle(
                                                              color: Colors.grey, fontSize: 12.0),
                                                        ),

                                                      ],
                                                    ),
                                                  ),
                                                  new Row(
                                                    children: <Widget>[
                                                      new Text('          '),
                                                      new Flexible(
                                                        child: new Text(mymessage),
                                                      )
                                                    ],
                                                  ),
                                                  new Container(
                                                      width: 150.0,
                                                      child: new Row(
                                                        children: <Widget>[
                                                          new Text('          '),
                                                          _showGraphic()
                                                        ],
                                                      )),
                                                ],
                                              ),
                                            ),
                                          );
                                        });
                                        return new Column(children: messagelist);
                                    }
                                  }
                                );
                                /*return new MyChatWidget(
                                  datediv: snapshot.data[index]['msgdate'],
                                  msgkey: snapshot.data[index]['msgkey'],
                                );*/

                              },
                              //itemBuilder: _itemBuilder,
                              controller: _scrollController,
                              reverse: true,
                              itemCount: snapshot.data.length,
                            ),
                            onRefresh: _onRefresh
                        );
                      }

                  }
                }),
新建StreamBuilder(
initialData:myInitialData,
流:msgstream,
生成器:(BuildContext上下文,异步快照){
交换机(快照.连接状态){
案例连接状态。无:
返回新文本(“等待开始”);
案例连接状态。正在等待:
返回新文本(“”);
违约:
if(snapshot.hasError){
返回新文本('Error:${snapshot.Error}');
}否则{
myInitialData=snapshot.data;
返回新的刷新指示器(
子项:新建ListView.builder(
itemBuilder:(上下文,索引){
流msgstream2;
Future _responseDate=ChatDB.instance.getMessagesByDate(snapshot.data[index]['msgkey'],snapshot.data[index]['msgdate']);
msgstream2=来自未来的新流(_responseDate);
返回新的StreamBuilder(
initialData:myInitialData2,
流:msgstream2,
生成器:(BuildContext上下文,异步快照){
交换机(快照.连接状态){
案例连接状态。无:
返回新文本(“等待开始”);
案例连接状态。正在等待:
返回新文本(“”);
违约:
名单;
var mybytes;
文件myimageview;
图像视图;
字符串imgStr;
字符串vidStr;
字符串vidimgstr;
myInitialData2=snapshot.data;
List json=snapshot.data;
List messagelist=[];
forEach((元素){
日期时间提交日期=
parse(元素['submitdate']).toLocal();
字符串myvideo=(元素['chatvideo']);
字符串myimage=element['chatimage'];
字符串myvideoimage=元素['chatvideoimage'];
文件imgfile;
文件-视频文件;
文件vidimgfile;
bool-vidInit=false;
未来(Future)推出,;
字符串localAssetPath;
字符串本地视频路径;
字符串mymessage=element['message'].replaceAll([\u2018\u2019],“”);
//打印('MYDATE:'+submitdate.toString());
_检查文件(文件)异步{
var checkfile=await file.exists();
打印('VIDEXISTS:'+checkfile.toString());
}
Future\u launchVideo(字符串url,bool isLocal)异步{
如果(等待canLaunchVideo(url,isLocal)){
等待启动视频(url,isLocal);
}否则{
抛出“无法启动$url”;
}
}
void\u launchLocal()=>
setState(()=>\u launched=\u launchVideo(localVideoPath,true)
);
Widget_showVideo(){
返回新的灵活(
孩子:新卡(
子:新列(
儿童:[
新建ListTile(副标题:新建文本(“视频”),标题:新建文本(元素['referralname'),),
新手势检测器(
onTap:_launchLocal,
子:新建Image.file(
维迪姆档案,
宽度:150.0,
),
),
],
),
)
);
}
如果(myimage!=“”){
class Server {
  StreamController<List<Map>> _controller = new StreamController.broadcast();
  void addMessage(int message) {
    var newmsg = await database.rawQuery('select c.*, date(submitdate, "localtime") as msgtime from v_groupchats g join chats c on c.id = g.id where (oid = $oid or prid = $prid) and c.msgkey not in (select msgkey from chatArchive) order by submitdate desc');
    _controller.add(message);
  }
  Stream get messages => _controller.stream;
}
case ConnectionState.waiting:
  return new Text('');