gpt4 book ai didi

flutter - Flutter 中具有最小高度的扩展小部件

转载 作者:行者123 更新时间:2023-12-03 13:30:02 30 4
gpt4 key购买 nike

我的问题的上下文:Expanded小部件 缩水 它的子小部件到 零高度 如果需要和 忽略 它的 child 约束 .
目标:预防 扩展 widget从缩小到小于其子尺寸 这样它的小部件就不会被破坏。
另外,我需要小部件到占用所有可用空间并展开它的 child 。
边注:Container用于分配高度空间使expanded对空间变化使用react
这是代码:

import 'package:flutter/material.dart';

class MainScreen extends StatelessWidget {
const MainScreen({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
child: Card(
color: Colors.blueAccent,
child: LimitedBox(
maxHeight: 200,
child: Text(
'Test dummy text Test dummy text Test dummy text Test dummy text Test dummy text Test dummy text Test dummy text Test dummy text Test dummy text Test dummy text ',
style: TextStyle(fontSize: 60, color: Colors.black),
),
),
),
),
Container(
color: Colors.amberAccent,
height: 105,
width: 200,
)
],
),
);
}
}

这是不需要的电流输出:
Expanded behavior that is required Expanded正常行为:
Shrinking behavior that is NOT required

最佳答案

使用 Flexible小部件并添加 Container使用 min-height,蓝色容器的大小会随着文本的增加而增加。

 Scaffold(
appBar: AppBar(),
body: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
child: Container(
constraints: BoxConstraints(
minHeight: 200, minWidth: double.infinity),
child: Card(
color: Colors.blueAccent,
child: Text(
'Sample Text',
style: TextStyle(fontSize: 60, color: Colors.black),
),
),
),
),
Container(
color: Colors.amberAccent,
height: 105,
width: 200,
)
],
),
)
),
输出:
enter image description here

关于flutter - Flutter 中具有最小高度的扩展小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62653648/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com