无效参数:超过了对堆栈大小的最大调用



这是我的主屏幕dart文件

import 'package:flutter/material.dart';
import './components/body.dart';
import '../model/product.dart';
class HomeScreen extends StatelessWidget {
get product => this.product;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildAppBar(),
body: buildBody(),
);
}
AppBar buildAppBar() {
return AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(icon: Icon(Icons.arrow_back, color: Colors.black), onPressed: () {}), //iconbutton
actions: <Widget>[
IconButton(icon: Icon(Icons.search, color: Colors.black), onPressed: () {}), //iconbutton
IconButton(icon: Icon(Icons.shopping_cart, color: Colors.black), onPressed: () {}), //iconbutton
], //<widget>
); //appBar
}
Body buildBody() {
return Body(product: this.product);
}
}

运行时显示的错误是

获取产品包/shoppingapp/screens/home_screen。飞镖6:23

包/颤振/src/widget/框架。dart 3363:18 updatecchild

包/颤振/src/widget/框架。零件6083:14安装

包/颤振/src/widget/框架。dart 3611:13 inflateWidget

包/颤振/src/widget/框架。dart 3363:18 updatecchild

包/颤振/src/widget/框架。dart 4599:16 performRebuild

包/颤振/src/widget/框架。Dart 4267:5 rebuild

包/颤振/src/widget/框架。dart 4553:5 [_firstBuild]

包/颤振/src/widget/绑定。飞镖1104:16

包/颤振/src/widget/框架。dart 2535:19 buildScope

包/颤振/src/widget/绑定。dart 1103:12 attachToRenderTree

包/颤振/src/widget/绑定。dart 936:24 attachRootWidget

包/颤振/src/widget/绑定。飞镖917:7

dart:sdk_internal 25312:11 internalCallback测试时模拟器显示错误。

无效参数:栈大小的最大调用超过

import 'package:flutter/material.dart';
import '../../../model/product.dart';
import '../../../constants.dart';
import 'add_to_cart.dart';
import 'color_and_size.dart';
import 'description.dart';
import 'product_title_with_image.dart';
import 'package:shoppingapp/screens/details/components/counter_with_fav_btn.dart';
class Body extends StatelessWidget {
final Product product;
const Body({Key? key, required this.product}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return SingleChildScrollView(
child: Column(
children: <Widget>[
SizedBox(
height: size.height,
child: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: size.height * 12, left: kDefaultPadding, right: kDefaultPadding), //edgeinsets
margin: EdgeInsets.only(top: size.height * 0.3),
height: 500,
decoration: BoxDecoration(
color: Colors.white, //boxdecoration
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24),
), //boxdecoration
), //borderradius
child: Column(
children: <Widget>[
ColorAndSize(product: product), //colorand size
SizedBox(height: kDefaultPadding / 2), //sizedbox
Description(product: product),
SizedBox(height: kDefaultPadding / 2), //sizedbox
CounterWithFavBtn(), //counterwithfavbtn
SizedBox(height: kDefaultPadding / 2), //sizedbox
AddToCart(product: product), //addtocart
], //widget
), //column
), //container
ProductTitleWithImage(product: product),
], //widget
), //stack
), //sizedbox
], //widget
), //column
); //singlechildscrollview
}
}

任何帮助都是有用的谢谢你

你有递归getter

class HomeScreen extends StatelessWidget {
get product => this.product; // <—

使用这个lint规则递归getter来避免这种情况再次发生

最新更新