![](/img/trans.png)
[英]How to make whole screen scrollable include appbar scaffold in flutter
[英]Flutter - How to make SvgPicture.asset() take full screen inside of Slack with main parent Scaffold without Appbar
我想讓 SvgPicture 采用全寬和全高。 這是當前的解決方案。
我目前使用double.infinity
作為寬度和高度。 但是,我想讓它使用LayoutBuilder
的約束來使圖像全寬和全高。
LayoutBuilder(
builder: (layoutBuilderContext, constraints) {
return Stack(
children: [
SvgPicture.asset(
'assets/images/welcome/bg-welcome-screen.svg',
fit: BoxFit.cover,
width: double.infinity,
height: double.infinity,
),
]),
})
但是,使用constraints.maxWidth
和constraints.maxHeight
來調整SvgPicture
的大小是無法做到的。 它需要全高,但不能全寬。
如果可能的話,如何在不使用double.infinity
的情況下將圖像調整為全寬。 我真的希望它采用全屏寬度和高度,因為它是應用程序的背景圖像。
要獲取堆棧的完整大小,請使用Positioned.fill
,並且要調整 Stack 小部件的大小,請使用SizedBox
包裝Stack
SizedBox(
width: constraints.maxWidth,
height:constraints.maxHeight,
child: Stack(
children: [
Positioned.fill(
child: Text(""),
),
],
),
),
最好在腳手架的主體等頂級小部件上使用LayoutBuilder
來獲取主體大小。
更多關於Stack
您是否嘗試過使用 BoxFit.fill? 這將通過扭曲圖像的原始縱橫比來填充目標寬度和高度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.