gpt4 book ai didi

firebase - 手势 : Stack Overflow 捕获的异常

转载 作者:行者123 更新时间:2023-12-03 02:59:54 25 4
gpt4 key购买 nike

每次我点击 ListView 卡时,此错误都会显示“手势捕获的异常:堆栈溢出”,如此屏幕截图所示(https://www.screencast.com/t/udA8NZZ1AqsD)
这里的问题出在 Gesturedetector 的 onTap 代码中
截图列表
默认导航 PageRoute -> https://www.screencast.com/t/qKZQgaraFi
使用名为“test”的纯文本 -> https://www.screencast.com/t/XOxGkANLZEjC
导航页面路线略有变化 -> https://www.screencast.com/t/1F82pyQtQ2v9
带有新附加代码的手势检测器 -> https://www.screencast.com/t/hRefONV3o
从 firebase 传递数据的代码 -> https://www.screencast.com/t/24gc9zqfxmGX
结果链接:
结果 #1 -> https://www.screencast.com/t/PmiC5U6S2L
结果 #2 -> https://www.screencast.com/t/udA8NZZ1AqsD
我已经尝试了以下
尝试 1
尝试了默认的导航页面路由,并且 Gesturedetector 工作正常。缺点是我只能显示文本(请参阅上面的链接,仅使用名为“test”的纯文本)并且无法使用提供程序包 flutter 传递数据,如此屏幕截图所示
默认导航页面路由

GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => ProductDetail()));
},
)
使用名为“test”的纯文本
Text(
'test',
style: TextStyle(
fontSize: 35.0,
color: Colors.black45,
fontWeight: FontWeight.w700
),
),
结果:见结果#1
尝试 2
尝试了略有变化的导航页面路线(请参阅上面的链接“略有变化的导航页面路线”)以及普通文本(请参阅上面的链接 = 仅使用名为“测试”的纯文本)
导航页面路由
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute (builder: (BuildContext context) {
return ProductDetail();
})
);
},
使用名为“test”的纯文本
Text(
'test',
style: TextStyle(
fontSize: 35.0,
color: Colors.black45,
fontWeight: FontWeight.w700
),
),
结果:见结果#1
尝试 3
尝试使用新的附加代码(参见上面的“带有新附加代码的手势检测器”的链接)和普通文本(参见上面的链接,使用名为“测试”的纯文本)
导航页面路由
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
),
),
结果:见结果#2
尝试 4
使用新的附加代码(请参阅上面的“带有新附加代码的手势检测器”的链接)以及从 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,
),
),
),
),
],
)
);
}
),
),
);

}
}

最佳答案

问题是你在 set 方法中再次递归调用 set 方法(因此堆栈溢出)

set currentProditem(Proditem proditem){
currentProditem = proditem; //forgot the underscore,
// it should be _currentProditem = proditem;
// To change the variables not the setter again
notifylisteners();
}

关于firebase - 手势 : Stack Overflow 捕获的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62856375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com