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
Flutter 如何在带有滚动的列中使用分馏lysizedbox?_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 如何在带有滚动的列中使用分馏lysizedbox?

Flutter 如何在带有滚动的列中使用分馏lysizedbox?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我的颤振应用程序中有一个简单的布局: Scaffold( resizeToAvoidBottomInset: true, appBar: AppBar(centerTitle: true, title: Text('test')), body: SingleChildScrollView( child: Column( children: [ Expanded( flex: 7, child: Column(

我的颤振应用程序中有一个简单的布局:

Scaffold(
  resizeToAvoidBottomInset: true,
  appBar: AppBar(centerTitle: true, title: Text('test')),
  body: SingleChildScrollView(
    child: Column(
      children: [
        Expanded(
          flex: 7,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              FractionallySizedBox(
                widthFactor: 0.55,
                child: Padding(
                  padding: const EdgeInsets.symmetric(vertical: 10),
                  child: TextField(),
                ),
              ),
              SizedBox(
                height: 15,
              ),
            ],
          ),
        ),
        Expanded(
            child: Column(
          children: [
            Text('some text'),
            FractionallySizedBox(
              widthFactor: 0.55,
              child: RaisedButton(
                child: Text('Hello'),
              ),
            ),
          ],
        ))
      ],
    ),
  ),
);
它可以工作,但没有SingleChildScrollView。对于SingleChildScrollView,我有一个错误:

RenderBox was not laid out: RenderRepaintBoundary#0b8c5 relayoutBoundary=up1 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'
我需要字段和按钮占据相同的宽度——为此,我使用了FractillySizedBox

此外,我还需要按比例分割屏幕(在高度上)——为此,我使用Expanded with Flex

但我也需要在键盘出现时滚动。如果我使用SingleChildScrollView,它会给出一个错误。也许这不是最好的办法——如果您有任何建议,我将不胜感激


我使用了几个选项,但我得到了这个错误。如何修复此问题?

您可以复制下面的粘贴运行完整代码
步骤1:使用
LayoutBuilder
wrap
SingleChildScrollView
ConstrainedBox

第二步:
raised按钮
使用
展开

您可以看到下面的工作演示
代码片段

body: LayoutBuilder(
            builder: (BuildContext context, BoxConstraints constraints) {
          return SingleChildScrollView(
            child: ConstrainedBox(
              constraints: constraints.copyWith(
                maxHeight: constraints.maxHeight,
              ),
              child: Column(
              
  ...
  Expanded(
        flex: 3,
        child: RaisedButton(
          onPressed: () {
            print("hi");              
工作演示

完整代码

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        //resizeToAvoidBottomInset: true,
        appBar: AppBar(centerTitle: true, title: Text('test')),
        body: LayoutBuilder(
            builder: (BuildContext context, BoxConstraints constraints) {
          return SingleChildScrollView(
            child: ConstrainedBox(
              constraints: constraints.copyWith(
                maxHeight: constraints.maxHeight,
              ),
              child: Column(
                children: [
                  Expanded(
                    flex: 7,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.stretch,
                      children: [
                        FractionallySizedBox(
                          widthFactor: 0.55,
                          child: Padding(
                            padding: const EdgeInsets.symmetric(vertical: 10),
                            child: TextField(),
                          ),
                        ),
                        SizedBox(
                          height: 15,
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                      child: Column(
                    children: [
                      Text('some text'),
                      Expanded(
                        flex: 3,
                        child: RaisedButton(
                          onPressed: () {
                            print("hi");
                          },
                          child: Text('Hello'),
                        ),
                      ),
                    ],
                  ))
                ],
              ),
            ),
          );
        }));
  }
}
导入“包装:颤振/材料.省道”;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
视觉密度:视觉密度。自适应平台密度,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
//resizeToAvoidBottomInset:true,
appBar:appBar(中心标题:true,标题:Text('test')),
正文:布局生成器(
生成器:(BuildContext上下文,BoxConstraints){
返回SingleChildScrollView(
子:约束框(
约束:constraints.copyWith(
maxHeight:constraints.maxHeight,
),
子:列(
儿童:[
扩大(
弹性:7,
子:列(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
部分溶解箱(
宽度系数:0.55,
孩子:填充(
填充:常量边集。对称(垂直:10),
子项:TextField(),
),
),
大小盒子(
身高:15,
),
],
),
),
扩大(
子:列(
儿童:[
文本(“某些文本”),
扩大(
弹性:3,
孩子:升起按钮(
已按下:(){
打印(“hi”);
},
child:Text('Hello'),
),
),
],
))
],
),
),
);
}));
}
}