Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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
Flutter 在SingleChildScrollView小部件中将小部件扩展为最小高度_Flutter_Flutter Layout - Fatal编程技术网

Flutter 在SingleChildScrollView小部件中将小部件扩展为最小高度

Flutter 在SingleChildScrollView小部件中将小部件扩展为最小高度,flutter,flutter-layout,Flutter,Flutter Layout,这是我的密码 child: Scaffold( resizeToAvoidBottomPadding: false, appBar: AppBar(), drawer: MyDrawer(), body: SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.min, // directio

这是我的密码

child: Scaffold(
        resizeToAvoidBottomPadding: false,
        appBar: AppBar(),
        drawer: MyDrawer(),
        body: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            // direction: Axis.vertical,
            children: [
              Container(
                height: 400,
                child: Text('PageOne'),
              ),
              IntrinsicHeight(
                child: Expanded(
                  child: Container(
                    width: double.infinity,
                    color: Colors.grey,
                    child: Text(
                      'Hi',
                      textAlign: TextAlign.center,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
我希望屏幕截图中的这个灰色容器将高度填充为最小高度,我需要它与旋转屏幕手机一起响应,对于所有手机屏幕大小,使用SingleChildScrollView时它只会采用静态高度大小,因为可以使用无限高度,我想办法让他把屏幕的剩余高度作为容器的最小高度

有什么想法吗


如果您知道顶部的高度,您可以使用LayoutBuilder和ConstrainedBox的组合,如下所示:

import 'dart:math';

import 'package:flutter/material.dart';

main() {
  runApp(MaterialApp(home: MyApp()));
}

class MyApp extends StatelessWidget {
  final double headerHeight = 400;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      appBar: AppBar(),
      body: LayoutBuilder(
          builder: (BuildContext context, BoxConstraints constraints) {
            return SingleChildScrollView(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                // direction: Axis.vertical,
                children: [
                  Container(
                    color: Colors.red,
                    height: headerHeight,
                    child: Text('PageOne'),
                  ),
                  ConstrainedBox(
                    constraints: new BoxConstraints(
                      minHeight: max(0, constraints.maxHeight - headerHeight),
                    ),
                    child: Container(
                      width: double.infinity,
                      color: Colors.grey,
                      child: Text(
                        'Hi',
                        textAlign: TextAlign.center,
                      ),
                    ),
                  ),
                ],
              ),
            );
          }
      ),
    );
  }
}

如果您不知道顶部的高度,我会使用键(或多个键)获取它们的大小,并使用与上面相同的小部件树。

如果希望底部矩形填充剩余空间,为什么要使用滚动视图?我的意思是,如果矩形前的内容比屏幕大,为什么会发生这种情况?在这种情况下,您不希望显示任何矩形?如果包含更多文本或小部件,则灰色容器可能会变大,因此我需要滚动@D.lucasedid并解决,这只是一个负值问题,我刚刚添加了max(0,…)。