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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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
Dart 颤振-限制小部件以匹配其他小部件的高度_Dart_Flutter_Flutter Layout - Fatal编程技术网

Dart 颤振-限制小部件以匹配其他小部件的高度

Dart 颤振-限制小部件以匹配其他小部件的高度,dart,flutter,flutter-layout,Dart,Flutter,Flutter Layout,我想创建带有照片的列表项小部件,并在这张照片的右侧显示一些信息。由于web图像可能太大,我还希望我的照片小部件的高度(同时保持纵横比)与“内容”小部件的高度相匹配,可能没有给出明确的高度。 目前,我的小部件如下所示: 在安卓系统中,我会通过以下方式限制图像大小: constraintTop_toTopOf(内容ID) constraintBottom_toBottomOf(contentId) 有可能在颤振中做类似的事情吗? 目前,我的代码如下所示(我希望避免在ConstrainedBox的“

我想创建带有照片的列表项小部件,并在这张照片的右侧显示一些信息。由于web图像可能太大,我还希望我的照片小部件的高度(同时保持纵横比)与“内容”小部件的高度相匹配,可能没有给出明确的高度。 目前,我的小部件如下所示:

在安卓系统中,我会通过以下方式限制图像大小: constraintTop_toTopOf(内容ID) constraintBottom_toBottomOf(contentId)

有可能在颤振中做类似的事情吗? 目前,我的代码如下所示(我希望避免在ConstrainedBox的“maxHeight”参数中给出显式高度):


如果我必须获得所需的布局,我将使用-
ListTile
widget.
ListTile(前导:CircleAvatar(maxRadius:30.0,backgroundImage:NetworkImage()https://placeimg.com/640/480/any,标题:Padding(Padding:const EdgeInsets.only(底部:8.0,右侧:8.0),子级:Text('john Doe'),),副标题:Column(crossAxisAlignment:crossAxisAlignment.start,children:[Text('Manager'),Text('Company name'),],),)
看看它是否对您有帮助。如果我必须获得所需的布局,我会使用-
ListTile
小部件。
ListTile(前导:CircleAvatar(maxRadius:30.0,backgroundImage:NetworkImage()https://placeimg.com/640/480/any,标题:Padding(Padding:const EdgeInsets.only(底部:8.0,右侧:8.0),子级:Text('john Doe'),),副标题:Column(crossAxisAlignment:crossAxisAlignment.start,children:[文本('Manager')、文本('Company name')、]、),),)
查看它是否对您有帮助。
class SpeakerItemWidget extends StatelessWidget{

  final Speaker _speaker;

  SpeakerItemWidget(this._speaker);

  Widget _speakerItemContent() =>
      Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            '${_speaker.name} ${_speaker.surname}',
            style: TitleTextStyle(),
          ),
          SizedBox(height: Margin.small),
          Text(
            _speaker.title,
            style: DescriptionTextStyle(),
          ),
          Text(
            _speaker.company,
            style: DescriptionTextStyle(),
          )
        ],
      );

  @override
  Widget build(BuildContext context) =>
      InkWell(
        splashColor: Theme.of(context).accentColor,
        onTap: () => debugPrint('open event details'),
        child: Padding(
          padding: EdgeInsets.all(Margin.small),
          child: ConstrainedBox(
            constraints: BoxConstraints(
              maxHeight: 60,
            ),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                FittedBox(
                  fit: BoxFit.contain,
                  child: SpeakerPhotoWidget(_speaker),
                ),
                _speakerItemContent(),
              ],
            ),
          ),
        ),
      );
}
class SpeakerPhotoWidget extends StatelessWidget{

  final Speaker _speaker;

  SpeakerPhotoWidget(this._speaker);

  @override
  Widget build(BuildContext context) {

    return  ConstrainedBox(
      constraints: BoxConstraints(
        //initial size of widget is 0,0 - causes crash when inside FittedBox
        minHeight: 1,
        minWidth: 1,
      ),
      child: Padding(
        padding: EdgeInsets.only(right: Margin.small),
        child: FadeInImage.assetNetwork(
          placeholder: 'assets/images/speaker_placeholder.png',
          image: 'some uri',
          fit: BoxFit.contain,
        ),
      )
    );
  }
}