Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.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

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
Android 添加文本字段时,颤振屏幕显示为空_Android_Dart_Flutter_Textfield - Fatal编程技术网

Android 添加文本字段时,颤振屏幕显示为空

Android 添加文本字段时,颤振屏幕显示为空,android,dart,flutter,textfield,Android,Dart,Flutter,Textfield,我正在制作一个颤振应用程序,其中有一个文本,它正在工作,但在那之后,当我添加一个文本字段时,我运行了该应用程序,我发现该应用程序是空的 这是我的代码: import 'package:flutter/material.dart'; void main() { runApp(new MaterialApp( home: new MyApp(), )); } class MyApp extends StatelessWidget { @override Scaffold

我正在制作一个颤振应用程序,其中有一个文本,它正在工作,但在那之后,当我添加一个文本字段时,我运行了该应用程序,我发现该应用程序是空的

这是我的代码:

import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(
    home: new MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  @override
  Scaffold c = Scaffold(
    body: Padding(
      padding: const EdgeInsets.only(top:30.0),
      child: new Row(
        children: <Widget>[
          new TextField(
            decoration: InputDecoration(
                border: InputBorder.none,
                hintText: 'Please enter a search term'
            ),
          ),
          new Text(
            'Text',
            style: TextStyle(
              fontSize: 20.0
            ),
          ),
        ],
      ),
    ),
  );

  @override
  Widget build(BuildContext context) {
    return c;
  }
}
导入“包装:颤振/材料.省道”;
void main(){
runApp(新材料)PP(
主页:新建MyApp(),
));
}
类MyApp扩展了无状态小部件{
@凌驾
脚手架c=脚手架(
主体:填充物(
填充:仅限常量边集(顶部:30.0),
孩子:新的一排(
儿童:[
新文本字段(
装饰:输入装饰(
边框:InputBorder.none,
hintText:'请输入搜索词'
),
),
新文本(
“文本”,
样式:TextStyle(
字体大小:20.0
),
),
],
),
),
);
@凌驾
小部件构建(构建上下文){
返回c;
}
}

这是因为
容器不知道
文本字段
小部件的大小

这是您得到的错误:

    following function, which probably computed the invalid constraints in question:
        flutter:   _RenderDecoration._layout.layoutLineBox 
      (package:flutter/src/material/input_decorator.dart:808:11)
        flutter: The offending constraints were:
        flutter:   BoxConstraints(w=Infinity, 0.0<=h<=379.0)
但它在屏幕上看起来很奇怪,因此您可以改进使用Flexible作为
TextField
Text

        Scaffold c = Scaffold(
            body: Padding(
              padding: const EdgeInsets.only(top:30.0),
              child: new Row(
                children: <Widget>[
                  Flexible(
                    flex: 1,
                              child: new TextField(
                      decoration: InputDecoration(
                          border: InputBorder.none,
                          hintText: 'Please enter a search term'
                      ),
                    ),
                  ),
                  Flexible(
                    flex: 1,
                              child: new Text(
                      'Text',
                      style: TextStyle(
                        fontSize: 20.0
                      ),
                    ),
                  ),
                ],
              ),
            ),
          );
Scaffold c=脚手架(
主体:填充物(
填充:仅限常量边集(顶部:30.0),
孩子:新的一排(
儿童:[
灵活的(
弹性:1,
孩子:新文本字段(
装饰:输入装饰(
边框:InputBorder.none,
hintText:'请输入搜索词'
),
),
),
灵活的(
弹性:1,
儿童:新文本(
“文本”,
样式:TextStyle(
字体大小:20.0
),
),
),
],
),
),
);

flexible做什么?你可以阅读更多关于这方面的内容:,基本上,在这个例子中,flexible就像androidy中的一个砝码,你不必添加
flexible:1,
它是默认值
        Scaffold c = Scaffold(
            body: Padding(
              padding: const EdgeInsets.only(top:30.0),
              child: new Row(
                children: <Widget>[
                  Flexible(
                    flex: 1,
                              child: new TextField(
                      decoration: InputDecoration(
                          border: InputBorder.none,
                          hintText: 'Please enter a search term'
                      ),
                    ),
                  ),
                  Flexible(
                    flex: 1,
                              child: new Text(
                      'Text',
                      style: TextStyle(
                        fontSize: 20.0
                      ),
                    ),
                  ),
                ],
              ),
            ),
          );