如何解决在paint期间抛出:'package:flutter/src/rendering/sliver_multi_box_adaptor.dart':失败的断言:第544行位置12:'child.hasSize':不是真的
我想构建一个旋转木马滑块,显示我之前制作的列表的产品图像,带有一个 onpressed 功能,可以导航到另一个显示点击产品详细信息的路线,我的产品列表名称为 List.
当我在 Home_Page Route 中调用 Carousel Slider 方法时,我需要“itemBuilder: (context,index)”,所以我将它包装在 ListView.builder 中并将其包装到一个具有定义高度和宽度的容器中以避免错误上面,但在运行应用程序时,在 Carousel Slider 应该在的地方没有任何显示......我这样做对吗?
我的轮播滑块代码:
class CustomCarouselHomePage extends StatefulWidget {
final List<String> Productzz;
final Function press;
final Productz productz;
CustomCarouselHomePage(
{required this.Productzz,required this.press,required this.productz});
@override
_CustomCarouselHomePageState createState() => _CustomCarouselHomePageState();
}
class _CustomCarouselHomePageState extends State<CustomCarouselHomePage> {
int activeIndex = 0;
late final Function press;
late final Productz productz;
setActiveDot(index) {
setState(() {
activeIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Stack(
clipBehavior: Clip.none,children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,child: CarouselSlider(
options: CarouselOptions(
autoplayInterval: Duration(seconds: 4),autoplayCurve: Curves.fastLinearToslowEaseIn,autoplayAnimationDuration: Duration(seconds: 2),viewportFraction: 1.0,onPageChanged: (index,reason) {
setActiveDot(index);
},),items: widget.Productzz.map((productzz) {
return Builder(
builder: (BuildContext context) {
return GestureDetector(
onTap: () => press (),child: Stack(
// crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,child: Hero(
tag: "${productz.id}",child: Image.asset(productz.item_image),Container(
width: MediaQuery.of(context).size.width,color: Colors.black.withOpacity(0.2),],);
},);
}).toList(),Positioned(
left: 0,right: 0,bottom: 10,child: Row(
mainAxisAlignment: MainAxisAlignment.end,children: List.generate(widget.Productzz.length,(idx) {
return activeIndex == idx ? ActiveDot() : InactiveDot();
})),)
],);
}
}
class ActiveDot extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(right: 8.0),child: Container(
width: 25,height: 8,decoration: Boxdecoration(
color: white,borderRadius: BorderRadius.circular(5),);
}
}
class InactiveDot extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(right: 8.0),child: Container(
width: 8,decoration: Boxdecoration(
color: grey,);
}
}
当我在 Home_Page Route 中调用 Carousel Slider 方法时的代码:
Container(
height:MediaQuery.of(context).size.height,child: ListView.builder(
itemBuilder: (context,index) => CustomCarouselHomePage(
Productzz: [],productz: productz[index],press: () => Navigator.push(
context,MaterialPageRoute(
builder: (context) => DetailsScreen(
productz: productz[index],)),
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。