Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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 如何在Flatter中的CustomScrollView中使用可驳回的小部件?_Dart_Flutter_Custom Scrolling - Fatal编程技术网

Dart 如何在Flatter中的CustomScrollView中使用可驳回的小部件?

Dart 如何在Flatter中的CustomScrollView中使用可驳回的小部件?,dart,flutter,custom-scrolling,Dart,Flutter,Custom Scrolling,我正在尝试在customscrollview中创建一个可拒绝的卡片列表。这些卡正在被渲染,但当我刷这些卡以消除它们时,它们不会从列表中删除。下面是代码。请帮忙 CustomScrollView customScroll = new CustomScrollView( slivers: <Widget>[ new SliverAppBar( backgroundColor: Colors.black, automaticallyI

我正在尝试在customscrollview中创建一个可拒绝的卡片列表。这些卡正在被渲染,但当我刷这些卡以消除它们时,它们不会从列表中删除。下面是代码。请帮忙

  CustomScrollView customScroll = new CustomScrollView(
    slivers: <Widget>[
      new SliverAppBar(
        backgroundColor: Colors.black,
        automaticallyImplyLeading: false,
        expandedHeight: 90.0,
        title: new Text("Test"),
      ),
      new SliverFixedExtentList(
        itemExtent: 128.0,
        delegate: new SliverChildBuilderDelegate(
              (BuildContext context, int index) {
              return new Dismissible(key: new ObjectKey(objects[index]),
              child: widget.widgetAdapter(objects[index]),
              onDismissed: (DismissDirection direction) {
                setState(() {
                  this.objects.removeAt(index);
                  this.reIndex();
                });
                direction == DismissDirection.endToStart ? print(
                    "favourite") : print("remove");
              },
              background: new Container(
                  color: const Color.fromRGBO(183, 28, 28, 0.8),
                  child: const ListTile(
                      leading: const Icon(
                          Icons.delete, color: Colors.white, size: 36.0)
                  )
              ),
              secondaryBackground: new Container(
                  color: const Color.fromRGBO(0, 96, 100, 0.8),
                  child: const ListTile(
                      trailing: const Icon(
                          Icons.favorite, color: Colors.white, size: 36.0)
                  )
              ),
            );
            },
           childCount: objects.length,
        ),
      ),
    ]
);
CustomScrollView customScroll=新建CustomScrollView(
条子:[
新滑杆(
背景颜色:Colors.black,
自动嵌入:false,
扩展高度:90.0,
标题:新文本(“测试”),
),
新SliverFixedExtentList(
itemExtent:128.0,
代表:新SliverChildBuilderDelegate(
(BuildContext上下文,int索引){
返回新的可驳回(键:new ObjectKey(对象[索引]),
子项:widget.widgetAdapter(对象[索引]),
onDismissed:(解除方向){
设置状态(){
this.objects.removeAt(索引);
这个.reIndex();
});
方向==DismissDirection.endToStart?打印(
“收藏夹”):打印(“删除”);
},
背景:新容器(
颜色:常量颜色。来自RGBO(183,28,28,0.8),
子:const listile(
引导:常量图标(
Icons.delete,颜色:Colors.white,大小:36.0)
)
),
第二个背景:新容器(
颜色:常量颜色。来自RGBO(0,96100,0.8),
子:const listile(
尾随:常量图标(
图标。收藏夹,颜色:颜色。白色,大小:36.0)
)
),
);
},
childCount:objects.length,
),
),
]
);

您的尝试基本上是正确的-我简化了列表创建,并在下面的示例代码中替换了它-您要查找的是dmiss函数@line 35

import 'package:flutter/material.dart';

class TestDismissCSV extends StatefulWidget {
  @override
  _TestDismissCSVState createState() => new _TestDismissCSVState();
}

class _TestDismissCSVState extends State<TestDismissCSV> {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: "Dismiss in Cust Scroll V",
      theme: new ThemeData(brightness: Brightness.dark),
      home: new Scaffold(
        body: dmiss(context),
      ),
    );
  }

  List<TheListClass> _theList;

  Widget dmiss(context) {
    return new CustomScrollView(slivers: <Widget>[
      new SliverAppBar(
        backgroundColor: Colors.black,
        automaticallyImplyLeading: false,
        expandedHeight: 90.0,
        title: new Text("Test"),
      ),
      new SliverFixedExtentList(
        itemExtent: 128.0,
        delegate: new SliverChildBuilderDelegate(
          (BuildContext context, int index) {
            return new Dismissible(
              key: new ObjectKey(_theList[index]),
              child: new Material(child: new Text(_theList[index].title)),
              onDismissed: (DismissDirection direction) {
                setState(() {
                  this._theList.removeAt(index);
                  //this.reIndex();
                });
                direction == DismissDirection.endToStart
                    ? print("favourite")
                    : print("remove");
              },
              background: new Container(
                  color: const Color.fromRGBO(183, 28, 28, 0.8),
                  child: const ListTile(
                      leading: const Icon(Icons.delete,
                          color: Colors.white, size: 36.0))),
              secondaryBackground: new Container(
                  color: const Color.fromRGBO(0, 96, 100, 0.8),
                  child: const ListTile(
                      trailing: const Icon(Icons.favorite,
                          color: Colors.white, size: 36.0))),
            );
          },
          childCount: _theList.length,
        ),
      ),
    ]);
  }

  @override
  void initState() {
    super.initState();
    _theList = new List<TheListClass>();

    for (var i = 0; i < 100; i++) {
      _theList.add(new TheListClass('List Item ' + i.toString()));
    }
  }

  @override
  void dispose() {
    super.dispose();
  }
}

class TheListClass {
  String title;

  TheListClass(this.title);
}
导入“包装:颤振/材料.省道”;
类TestDismissCSV扩展StatefulWidget{
@凌驾
_TestDismissCSVState createState()=>new_TestDismissCSVState();
}
类_TestDismissCSVState扩展状态{
@凌驾
小部件构建(构建上下文){
返回新材料PP(
标题:“在客户卷轴V中解散”,
主题:新主题数据(亮度:亮度.暗),
家:新脚手架(
正文:dmiss(上下文),
),
);
}
列表;
小部件DMIS(上下文){
返回新的CustomScrollView(条子:[
新滑杆(
背景颜色:Colors.black,
自动嵌入:false,
扩展高度:90.0,
标题:新文本(“测试”),
),
新SliverFixedExtentList(
itemExtent:128.0,
代表:新SliverChildBuilderDelegate(
(BuildContext上下文,int索引){
返回新的可驳回的(
key:newObjectKey(\u theList[index]),
子项:新材料(子项:新文本(_theList[index].title)),
onDismissed:(解除方向){
设置状态(){
此.\列表移除(索引);
//这个.reIndex();
});
方向==DismissDirection.endToStart
?打印(“收藏夹”)
:打印(“删除”);
},
背景:新容器(
颜色:常量颜色。来自RGBO(183,28,28,0.8),
子:const listile(
前导:常量图标(Icons.delete,
颜色:彩色。白色,尺寸:36.0),
第二个背景:新容器(
颜色:常量颜色。来自RGBO(0,96100,0.8),
子:const listile(
尾随:常量图标(Icons.favorite,
颜色:彩色。白色,尺寸:36.0),
);
},
childCount:\u the list.length,
),
),
]);
}
@凌驾
void initState(){
super.initState();
_列表=新列表();
对于(变量i=0;i<100;i++){
_add(新的listClass('List Item'+i.toString());
}
}
@凌驾
无效处置(){
super.dispose();
}
}
类列表类{
字符串标题;
ListClass(此标题);
}


快乐编码

您的尝试基本上是正确的-我简化了列表创建,并在下面的示例代码中替换了它-您要查找的是dmiss函数@line 35

import 'package:flutter/material.dart';

class TestDismissCSV extends StatefulWidget {
  @override
  _TestDismissCSVState createState() => new _TestDismissCSVState();
}

class _TestDismissCSVState extends State<TestDismissCSV> {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: "Dismiss in Cust Scroll V",
      theme: new ThemeData(brightness: Brightness.dark),
      home: new Scaffold(
        body: dmiss(context),
      ),
    );
  }

  List<TheListClass> _theList;

  Widget dmiss(context) {
    return new CustomScrollView(slivers: <Widget>[
      new SliverAppBar(
        backgroundColor: Colors.black,
        automaticallyImplyLeading: false,
        expandedHeight: 90.0,
        title: new Text("Test"),
      ),
      new SliverFixedExtentList(
        itemExtent: 128.0,
        delegate: new SliverChildBuilderDelegate(
          (BuildContext context, int index) {
            return new Dismissible(
              key: new ObjectKey(_theList[index]),
              child: new Material(child: new Text(_theList[index].title)),
              onDismissed: (DismissDirection direction) {
                setState(() {
                  this._theList.removeAt(index);
                  //this.reIndex();
                });
                direction == DismissDirection.endToStart
                    ? print("favourite")
                    : print("remove");
              },
              background: new Container(
                  color: const Color.fromRGBO(183, 28, 28, 0.8),
                  child: const ListTile(
                      leading: const Icon(Icons.delete,
                          color: Colors.white, size: 36.0))),
              secondaryBackground: new Container(
                  color: const Color.fromRGBO(0, 96, 100, 0.8),
                  child: const ListTile(
                      trailing: const Icon(Icons.favorite,
                          color: Colors.white, size: 36.0))),
            );
          },
          childCount: _theList.length,
        ),
      ),
    ]);
  }

  @override
  void initState() {
    super.initState();
    _theList = new List<TheListClass>();

    for (var i = 0; i < 100; i++) {
      _theList.add(new TheListClass('List Item ' + i.toString()));
    }
  }

  @override
  void dispose() {
    super.dispose();
  }
}

class TheListClass {
  String title;

  TheListClass(this.title);
}
导入“包装:颤振/材料.省道”;
类TestDismissCSV扩展StatefulWidget{
@凌驾
_TestDismissCSVState createState()=>new_TestDismissCSVState();
}
类_TestDismissCSVState扩展状态{
@凌驾
小部件构建(构建上下文){
返回新材料PP(
标题:“在客户卷轴V中解散”,
主题:新主题数据(亮度:亮度.暗),
家:新脚手架(
正文:dmiss(上下文),
),
);
}
列表;
小部件DMIS(上下文){
返回新的CustomScrollView(条子:[
新滑杆(
背景颜色:Colors.black,
自动嵌入:false,
扩展高度:90.0,
标题:新文本(“测试”),
),
新SliverFixedExtentList(
itemExtent:128.0,
代表:新SliverChildBuilderDelegate(
(BuildContext上下文,int索引){
返回新的可驳回的(
key:newObjectKey(\u theList[index]),
子项:新材料(子项:新文本(_theList[index].title)),
onDismissed:(解除方向){
设置状态(){
此.\列表移除(索引);
//这个.reIndex();
});
方向==DismissDirection.endToStart
?打印(“收藏夹”)