Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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
Firebase 手势捕获异常:堆栈溢出_Firebase_Flutter_Dart_Flutter Provider_Gesturedetector - Fatal编程技术网

Firebase 手势捕获异常:堆栈溢出

Firebase 手势捕获异常:堆栈溢出,firebase,flutter,dart,flutter-provider,gesturedetector,Firebase,Flutter,Dart,Flutter Provider,Gesturedetector,每次我点击ListView卡时,这个错误都会显示“由手势捕获的异常:堆栈溢出”,如屏幕截图所示() 这里的问题在Gesturedetector的onTap代码中的某个地方 截图列表 默认导航页面路由-> 只有一个名为“test”的纯文本-> 略为更改的导航页面路径-> 带有新附加代码的手势检测器-> 从firebase传递数据的代码-> 结果链接: 结果#1-> 结果#2-> 我尝试了以下方法 试试1 尝试了默认的导航页面路径,Gesturedetector工作正常。缺点是我只能显示文本(请参阅

每次我点击ListView卡时,这个错误都会显示“由手势捕获的异常:堆栈溢出”,如屏幕截图所示()

这里的问题在Gesturedetector的onTap代码中的某个地方

截图列表 默认导航页面路由-> 只有一个名为“test”的纯文本-> 略为更改的导航页面路径-> 带有新附加代码的手势检测器-> 从firebase传递数据的代码->

结果链接: 结果#1-> 结果#2->

我尝试了以下方法

试试1 尝试了默认的导航页面路径,Gesturedetector工作正常。缺点是我只能显示文本(请参阅上面的链接,其中只有一个名为“test”的纯文本),并且无法使用此屏幕截图上显示的提供程序包flift传递数据

默认导航页面路由

GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: () {
    Navigator.push(context, MaterialPageRoute(builder: (context) => ProductDetail()));
  },
)
GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: () {
    Navigator.of(context).push(
      MaterialPageRoute (builder: (BuildContext context) {
        return ProductDetail();
    })
  );
},
GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: () {
    itemNotifier.currentProditem = itemNotifier.itemList[index];
      Navigator.of(context).push(
        MaterialPageRoute (builder: (BuildContext context) {
          return ProductDetail();
      })
    );
  },
),

只需要一个名为“test”的纯文本

Text(
 'test',
 style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
Text(
  'test',
  style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
Text(
  'test',
  style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
结果:见结果#1

试试2 尝试了略作更改的导航页面路径(请参阅上面的链接“略作更改的导航页面路径”)和普通文本(请参阅上面的链接=仅使用名为“test”的纯文本)

导航页面路径

GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: () {
    Navigator.push(context, MaterialPageRoute(builder: (context) => ProductDetail()));
  },
)
GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: () {
    Navigator.of(context).push(
      MaterialPageRoute (builder: (BuildContext context) {
        return ProductDetail();
    })
  );
},
GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: () {
    itemNotifier.currentProditem = itemNotifier.itemList[index];
      Navigator.of(context).push(
        MaterialPageRoute (builder: (BuildContext context) {
          return ProductDetail();
      })
    );
  },
),

只需要一个名为“test”的纯文本

Text(
 'test',
 style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
Text(
  'test',
  style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
Text(
  'test',
  style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
结果:见结果#1

试试3 用一个新的附加代码(参见上面的链接“Gesturedetector with new additional code”)和普通文本(参见上面的链接,其中只有一个名为“test”的纯文本)

导航页面路径

GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: () {
    Navigator.push(context, MaterialPageRoute(builder: (context) => ProductDetail()));
  },
)
GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: () {
    Navigator.of(context).push(
      MaterialPageRoute (builder: (BuildContext context) {
        return ProductDetail();
    })
  );
},
GestureDetector(
  behavior: HitTestBehavior.translucent,
  onTap: () {
    itemNotifier.currentProditem = itemNotifier.itemList[index];
      Navigator.of(context).push(
        MaterialPageRoute (builder: (BuildContext context) {
          return ProductDetail();
      })
    );
  },
),

只需要一个名为“test”的纯文本

Text(
 'test',
 style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
Text(
  'test',
  style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
Text(
  'test',
  style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
结果:见结果#2

试试4 使用一个新的附加代码(请参见“Gesturedetector with new additional code”上面的链接)以及从firebase传递数据的代码(请参见“从firebase传递数据的代码”上面的链接)进行了尝试

从Firebase传递数据的代码

Text(
  (itemNotifier.currentProditem.price),
  style: TextStyle(
    fontSize: 35.0,
    color: Colors.black45,
    fontWeight: FontWeight.w700
  ),
),
结果:见结果#2

我的代码

Widget build(BuildContext context) {
    ItemNotifier itemNotifier = Provider.of<ItemNotifier>(context);
    return new Scaffold(
        backgroundColor: Color(0xffdcdcdc),
        appBar: new AppBar(
            centerTitle: true,
            title: new Text(
              'Discover Products',
              style: TextStyle(
                fontSize: 26.0,
                fontWeight: FontWeight.w600,
              ),
            ),
            backgroundColor: Color(0xFF352d5a)
        ),
        body: Padding(
          padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
            child: ListView.builder(
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                physics: ClampingScrollPhysics(),
                itemCount: itemNotifier.itemList.length == null ? 0 : itemNotifier.itemList.length,
                itemBuilder: (BuildContext context, index) {
                  return GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                       itemNotifier.currentProditem = itemNotifier.itemList[index];
                        Navigator.of(context).push(
                            MaterialPageRoute (builder: (BuildContext context) {
                              return ProductDetail();
                            })
                        );
                        // Navigator.push(context, MaterialPageRoute(builder: (context) => ProductDetail()));
                      },
                      child: Stack(
                        children: <Widget>[
                          Container(
                            margin: EdgeInsets.fromLTRB(40.0, 5.0, 20.0, 5.0),
                            height: 140.0,
                            width: double.infinity,
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(20.0),
                            ),
                            child: Padding(
                              padding: EdgeInsets.fromLTRB(
                                  100.0, 10.0, 20.0, 20.0),
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Column(
                                    mainAxisAlignment: MainAxisAlignment
                                        .spaceBetween,
                                    crossAxisAlignment: CrossAxisAlignment
                                        .start,
                                    children: <Widget>[
                                      Row(
                                        mainAxisAlignment: MainAxisAlignment
                                            .spaceBetween,
                                        children: <Widget>[
                                          Text(
                                            (itemNotifier.itemList[index].price),
                                            style: TextStyle(
                                                fontSize: 24.0,
                                                color: Colors.black45,
                                                fontWeight: FontWeight.w700
                                            ),
                                          ),
                                          IconButton(
                                            icon: Icon(Icons.favorite),
                                            color: Colors.grey.shade400,
                                            onPressed: () {
                                              setState(() {
                                                print('Go to Favorites');
                                              });
                                            },
                                          ),
                                        ],
                                      ),
                                       Container(
                                          width: 280.0,
                                          child: Text(
                                            (itemNotifier.itemList[index].producttitle),
                                            style: TextStyle(
                                                fontSize: 24.0,
                                                fontWeight: FontWeight.bold
                                            ),
                                            overflow: TextOverflow.ellipsis,
                                            maxLines: 1,
                                          ),
                                        ),
                                      SizedBox(
                                        height: 5.0,
                                      ),
                                    ],
                                  ),
                                  Container(
                                    width: 280.0,
                                    child: Text(
                                      (itemNotifier.itemList[index].description),
                                      style: TextStyle(
                                          color: Colors.grey
                                      ),
                                      overflow: TextOverflow.ellipsis,
                                      maxLines: 2,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                          Positioned(
                            left: 20.0,
                            top: 15.0,
                            bottom: 15.0,
                              child: Container(
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.circular(20.0),
                                  boxShadow: [
                                    BoxShadow(
                                      color: Colors.black26,
                                      offset: Offset(0.0, 2.0),
                                      blurRadius: 6.0,
                                    ),
                                  ],
                                ),
                                child: ClipRRect(
                                  borderRadius: BorderRadius.circular(20.0),
                                  child: Image(
                                    width: 110.0,
                                    image: AssetImage(
                                        'image'
                                    ),
                                    fit: BoxFit.cover,
                                  ),
                                ),
                              ),
                          ),
                        ],
                      )
                  );
                }
            ),
          ),
        );

  }
}
小部件构建(构建上下文){
ItemNotifier ItemNotifier=Provider.of(上下文);
归还新脚手架(
背景颜色:颜色(0xFFDCDC),
appBar:新的appBar(
标题:对,
标题:新文本(
“发现产品”,
样式:TextStyle(
字体大小:26.0,
fontWeight:fontWeight.w600,
),
),
背景颜色:颜色(0xFF352d5a)
),
主体:填充物(
填充:仅限边缘设置(顶部:10.0,底部:10.0),
子项:ListView.builder(
滚动方向:轴垂直,
收缩膜:对,
物理:ClampingScrollPhysics(),
itemCount:itemNotifier.itemList.length==null?0:itemNotifier.itemList.length,
itemBuilder:(构建上下文,索引){
返回手势检测器(
行为:HitTestBehavior.transparent,
onTap:(){
itemNotifier.currentProditem=itemNotifier.itemList[索引];
导航器.of(上下文).push(
MaterialPage路由(生成器:(构建上下文){
返回ProductDetail();
})
);
//push(context,MaterialPageRoute(builder:(context)=>ProductDetail());
},
子:堆栈(
儿童:[
容器(
边距:LTRB(40.0,5.0,20.0,5.0)的边距集,
身高:140.0,
宽度:double.infinity,
装饰:盒子装饰(
颜色:颜色,白色,
边界半径:边界半径。圆形(20.0),
),
孩子:填充(
填充:EdgeInsets.fromLTRB(
100.0, 10.0, 20.0, 20.0),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
纵队(
mainAxisAlignment:mainAxisAlignment
.spaceBetween,
crossAxisAlignment:crossAxisAlignment
开始
儿童:[
划船(
mainAxisAlignment:mainAxisAlignment
.spaceBetween,
儿童:[
正文(
(itemNotifier.itemList[index].price),
样式:TextStyle(
字体大小:24.0,
颜色:颜色。黑色45,
fontWeight:fontWeight.w700
),
),
图标按钮(
图标:图标(Icons.favorite),
颜色:Colors.grey.shade400,
已按下:(){
设置状态(){
打印(“转到收藏夹”);
});
},
),
],
),
包含