获取小部件的高度并将其传递给expandedHeight

问题描述 投票:0回答:1

我想在此处将图像作为AppBar的背景:

enter image description here

我知道的唯一方法是使用flexibleSpaceSliverAppBar(在CustomScrollView内部),因为普通的AppBar不会更改其大小以容纳图像。

问题是SliverAppBar需要经过硬编码的expandedHeight,并且我的每个屏幕都将显示具有不同高度的不同图像,因此我需要以编程方式获取高度并将其传递给expandedHeight。] >

是否有可能获得图像的未来高度,以使图像不会扭曲并填满屏幕的宽度,所以我可以将其传递给expandedHeight

我想在此处放置图像作为我的AppBar的背景:我知道的唯一方法是使用SliverAppBar的flexibleSpace(在CustomScrollView内),因为普通的AppBar不会更改它......] >

flutter flutter-layout
1个回答
0
投票

使用应用栏的flexibleSpace属性并使用your Image

AppBar(
        title: Text('My App'),
        flexibleSpace: Image(
          image: AssetImage('assets/image.png'), // or Image.asset and give your size to image using height and width property of Image.asset widget
          fit: BoxFit.cover,
        ),
© www.soinside.com 2019 - 2024. All rights reserved.