【发布时间】:2021-03-11 13:57:00
【问题描述】:
我有一行:
final Size _mediaQuery = MediaQuery.of(context).size;
File _storedImage;
return Row(
children: [
Container(
width: _mediaQuery.width * 0.45,
height: _mediaQuery.height * 0.35,
decoration:
BoxDecoration(border: Border.all(width: 1, color: Colors.grey)),
child: _storedImage != null
? Image.file(_storedImage, fit: BoxFit.cover, width: double.infinity)
: Text('No image picked',),
alignment: Alignment.center,
),
Expanded(
child: FlatButton.icon(
icon: Icon(Icons.camera),
label: Text('Take picture'),
textColor: Theme.of(context).primaryColor,
onPressed: () {},
),
),
],
);
该行在 android 设备上如下所示:
一个问题:
如果我给我的容器一个更大的宽度,比如width: _mediaQuery.width * 0.65,那么行项目将不再适合该行,并且右侧的小部件将从屏幕边界溢出:
我会收到这个错误:
A RenderFlex overflowed by 31 pixels on the right. The relevant error-causing widget was: _FlatButtonWithIcon
到目前为止我做了什么:
阅读flutter-how-to-fix-a-renderflex-overflowed-by-pixels-error
检查扩展文档 - https://api.flutter.dev/flutter/widgets/Expanded-class.html
我需要在我的行中进行哪些更改,以使“拍照”按钮适合该行,无论我的容器大小如何?
【问题讨论】:
标签: android flutter dart flutter-layout