我正在与一个问题作斗争,其中出现错误“对象在布局期间被赋予了无限大小”和“这可能意味着它是一个试图尽可能大的渲染对象,但它被放在另一个渲染中允许其子项选择自己大小的对象。”。
我理解它的含义,但不知道如何在仍然解决此问题的同时保持当前的小部件树响应(它在运行时呈现,因此对于前端用户来说似乎没有问题)。目前我没有设置某些东西的大小来保持响应,并且如果可能的话,我想避免硬编码小部件的大小。
非常感谢任何正确方向的帮助或指示:)
这是我当前的代码:
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"),
),
);
}
}
}