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
Flutter 颤振:在布局过程中,对象被赋予无限大的尺寸_Flutter_Dart_Layout_Flutter Layout_Flutter Widget - Fatal编程技术网

Flutter 颤振:在布局过程中,对象被赋予无限大的尺寸

Flutter 颤振:在布局过程中,对象被赋予无限大的尺寸,flutter,dart,layout,flutter-layout,flutter-widget,Flutter,Dart,Layout,Flutter Layout,Flutter Widget,我正在处理一个问题,在这个问题上,我遇到了一个错误“对象在布局过程中被赋予了无限大的尺寸。” 和 “这可能意味着它是一个试图尽可能大的渲染对象,但它被放在另一个渲染对象中,允许其子对象选择自己的大小。” 我理解这意味着什么,但我不知道如何在解决这个问题的同时仍然保持当前小部件树的响应性(它在运行时呈现,因此对于前端用户来说似乎没有问题)。目前我没有设置某些东西的大小以保持其响应性,如果可能的话,希望避免硬编码小部件的大小 非常感谢您向正确方向提供的任何帮助或指示:) 以下是我当前的代码:

我正在处理一个问题,在这个问题上,我遇到了一个错误“对象在布局过程中被赋予了无限大的尺寸。” 和 “这可能意味着它是一个试图尽可能大的渲染对象,但它被放在另一个渲染对象中,允许其子对象选择自己的大小。”

我理解这意味着什么,但我不知道如何在解决这个问题的同时仍然保持当前小部件树的响应性(它在运行时呈现,因此对于前端用户来说似乎没有问题)。目前我没有设置某些东西的大小以保持其响应性,如果可能的话,希望避免硬编码小部件的大小

非常感谢您向正确方向提供的任何帮助或指示:)

以下是我当前的代码:

    class EditArtikel extends StatefulWidget {
  final String path;

  EditArtikel({this.path});

  @override
  _EditArtikelState createState() => _EditArtikelState(path: path);
}

class _EditArtikelState extends State<EditArtikel> {
  final String path;

  _EditArtikelState({this.path});

  final titleController = TextEditingController();
  final subtitleController = TextEditingController();
  final authorController = TextEditingController();
  final textController = TextEditingController();

  File imageFile;

  List<DropdownMenuItem<dynamic>> dropdownMenuItemFromList() {
    List<DropdownMenuItem<dynamic>> itemsList = [];
    for (var i = 1; i < currentTags.length; i++) {
      itemsList.add(new DropdownMenuItem(
        child: Text(currentTags[i]),
        value: currentTags[i],
      ));
    }
    return itemsList;
  }

  var _selectedValue = "";

  @override
  Widget build(BuildContext context) {
    final isAdmin = Provider.of<bool>(context);
    var pathElements = path.split('/');
    final String artikelID = pathElements[3];
    List<DropdownMenuItem<dynamic>> items = dropdownMenuItemFromList();

    if (isAdmin == true) {
      return LayoutBuilder(
        builder: (context, constraint) {
          return GlobalScaffold(
            body: Container(
              height: constraint.maxHeight,
              child: SingleChildScrollView(
                child: StreamBuilder<ArtikelData>(
                    stream:
                        DatabaseService(pathID: artikelID).artikelByArtikelID,
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        titleController.text == ""
                            ? titleController.text = snapshot.data.title
                            : titleController.text;

                        subtitleController.text == ""
                            ? subtitleController.text = snapshot.data.subtitle
                            : subtitleController.text;

                        authorController.text == ""
                            ? authorController.text = snapshot.data.author
                            : authorController.text;

                        textController.text == ""
                            ? textController.text = snapshot.data.text
                            : textController.text;

                        _selectedValue == ""
                            ? _selectedValue =
                                currentTags.contains(snapshot.data.tags)
                                    ? snapshot.data.tags
                                    : currentTags[1]
                            : _selectedValue = _selectedValue;

                        FirebaseStorageImage fbImage = new FirebaseStorageImage(
                          fileName: artikelID,
                          storageLocation: fbRefArtiklarImages,
                        );

                        return Container(
                          color: primaryColor,
                          padding: EdgeInsets.symmetric(
                              horizontal: 20, vertical: 15),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  GradientHeading(
                                    large: true,
                                    text: "Redigera artikel",
                                  ),
                                  SizedBox(height: 15),
                                  CustomTextFormField(
                                    labelText: "Rubrik",
                                    controller: titleController,
                                  ),
                                  CustomTextFormField(
                                    labelText: "Underrubrik",
                                    controller: subtitleController,
                                  ),
                                  Padding(
                                    padding: EdgeInsets.only(bottom: 7),
                                    child: DropdownButtonFormField(
                                      decoration: customInputDecoration("Tags"),
                                      value: _selectedValue,
                                      isDense: true,
                                      onChanged: (value) {
                                        setState(() {
                                          _selectedValue = value;
                                        });
                                      },
                                      items: items,
                                    ),
                                  ),
                                  CustomTextFormField(
                                    labelText: "Skriven av",
                                    controller: authorController,
                                  ),
                                  CustomTextFormField(
                                    labelText: "Text",
                                    multiline: true,
                                    controller: textController,
                                  ),
                                  NormalButton(
                                    text: "Ladda upp ny bild",
                                    outlined: true,
                                    outlinedBgColor: primaryColor,
                                    onPressed: () async {
                                      FocusScope.of(context).unfocus();
                                      imageFile = await ChooseImage()
                                          .chooseImageFromGallery();
                                      setState(() {});
                                    },
                                  ),
                                  ConditionalBuilder(
                                    condition: imageFile == null,
                                    ifTrue: NormalButton(
                                      text: "Ta bort originalbild",
                                      shouldOverideColor: true,
                                      overriddenColor: redWarningColor,
                                      onPressed: () async {
                                        FocusScope.of(context).unfocus();
                                        showDialog(
                                          context: context,
                                          barrierDismissible: true,
                                          builder: (_) => AlertDialog(
                                            content: Text(
                                                "Vill du radera originalbilden?"),
                                            actions: <Widget>[
                                              FlatButton(
                                                child: Text("Avbryt"),
                                                onPressed: () {
                                                  Navigator.of(context).pop();
                                                },
                                              ),
                                              FlatButton(
                                                child: Text("Radera"),
                                                onPressed: () async {
                                                  await StorageService()
                                                      .deleteArtikelImageToStorage(
                                                          artikelID);
                                                  setState(() {});
                                                  Navigator.of(context).pop();
                                                },
                                              ),
                                            ],
                                          ),
                                        );
                                      },
                                    ),
                                  ),
                                  ConditionalBuilder(
                                    condition: imageFile != null,
                                    ifTrue: NormalButton(
                                      text: "Ta bort bild",
                                      shouldOverideColor: true,
                                      overriddenColor: redWarningColor,
                                      onPressed: () {
                                        FocusScope.of(context).unfocus();
                                        imageFile = null;
                                        setState(() {});
                                      },
                                    ),
                                  ),
                                  ConditionalBuilder(
                                    condition: imageFile != null,
                                    ifTrue: imageFile != null
                                        ? Image(
                                            image: FileImage(imageFile),
                                          )
                                        : Container(),
                                    ifFalse: fbImage,
                                  ),
                                  SizedBox(height: 40),
                                ],
                              ),
                              NormalButton(
                                text: "Publisera ändringar",
                                onPressed: () async {
                                  if (titleController.text != "" &&
                                      subtitleController.text != "" &&
                                      authorController.text != "" &&
                                      textController.text != "") {
                                    DatabaseService().editArtikel(
                                      artikelID,
                                      titleController.text,
                                      subtitleController.text,
                                      _selectedValue,
                                      authorController.text,
                                      textController.text,
                                      imageFile,
                                    );
                                    Navigator.pop(context);
                                  } else {
                                    showDialog(
                                      context: context,
                                      barrierDismissible: true,
                                      builder: (_) => AlertDialog(
                                        content:
                                            Text("Du måste fylla i alla fält"),
                                        actions: <Widget>[
                                          FlatButton(
                                            child: Text("OK"),
                                            onPressed: () {
                                              Navigator.of(context).pop();
                                            },
                                          )
                                        ],
                                      ),
                                    );
                                  }
                                },
                              ),
                            ],
                          ),
                        );
                      } else {
                        return LoadingWidget();
                      }
                    }),
              ),
            ),
          );
        },
      );
    } else {
      return GlobalScaffold(
        body: Center(
          child: Text("Du har inte tillgång till den här sidan"),
        ),
      );
    }
  }
}
class EditArtikel扩展StatefulWidget{
最终字符串路径;
EditArtikel({this.path});
@凌驾
_EditArtikelState createState()=>\u EditArtikelState(路径:路径);
}
类_EditArtikelState扩展状态{
最终字符串路径;
_EditArtikelState({this.path});
最终标题控制器=文本编辑控制器();
最终字幕控制器=TextEditingController();
最终authorController=TextEditingController();
final textController=TextEditingController();
文件图像文件;
List dropdownMenuItemFromList()列表{
列表项列表=[];
对于(var i=1;i

从我可以看到的地方,您遇到了问题,因为您正在
SingleChildScrollView
中插入
StreamBuilder
,该视图具有无限高的增长空间,并且
StreamBuilder
要求其家长的高度

StreamBuilder
需要一个具有固定大小的父对象,这样他就可以了解渲染其子对象所需的空间

您需要做的是将
SingleChildScrollView
放入一个具有给定大小的
容器中(您可以将所有主体放入
LayoutBuilder
中,并使用
约束。maxHeight
作为容器的高度,以便
SingleChildScrollView
知道其大小)

像这样:(因为我没有你的小部件,我不能运行这个代码…所以可能缺少一些括号)

我希望这有帮助

返回globalscafold(
正文:布局生成器(
生成器:(ctx,约束){
返回全局折叠(
主体:容器(
高度:constraints.maxHeight,
子:SingleChildScrollView(
子:容器(
填充:边缘组。对称(水平:20,垂直:15),
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
渐变标题(文本:“引导者”,大:真),
条件生成器(
病况:伊萨明,
如果是:列(
儿童:[
正常按钮(
文本:“斯卡帕纽约指南”,
已按下:(){
pushNamed(上下文,createNewArtikelRoute);
},
),
正常按钮(
文字:“Lägg直到ny kategori”,
是的,
按下:(){},
),
],
),
),
尺寸箱(高度:10),
StreamBuilder(
流:DatabaseService().guiderCategoriesByPopularity,
生成器:(上下文,快照){
if(snapshot.connectionState==connectionState.active){
返回指南类别(
快照:快照,
numberOfCategories:snapshot.data.length,
);
}如果(!snapshot.hasData){
返回指南类别(
hasNoCategories:没错,
);
}否则{
返回LoadingWidget();
}
},
),
],
),
),
),
),
);
}
)
);

您可以添加错误日志吗?。这里的大多数小部件都是您的自定义小部件。@CrazyLazyCat我现在添加了错误日志:)告诉我你是否需要一些特定小部件中的更多信息。另一个类似的问题可能发生在嵌套列小部件上,其中列试图占据所有可能的空间,所以他们将高度设置为无穷大,而第二列类似于“什么?你确定我可以无限大吗?”因此,解决方案是将每一列(或每一行)的子项包装在一个扩展的小部件中,这有助于在不硬编码特定大小的情况下管理约束。@DanielVofchuk感谢您!它在这个小部件中起作用。但当我尝试对另一个也有此问题的小部件进行相同的更改时,错误(相同的错误)仍然存在。我已经用新的小部件更新了我的问题(它有点复杂,我知道大多数小部件都是定制的,但我希望它仍然有效)。你知道这为什么不起作用吗