文本添加文本字段时,Flutter屏幕显示为空

文本添加文本字段时,Flutter屏幕显示为空,第1张

概述我在制作一个Flutter应用程序时,其中有一个文本,并且可以正常工作,但是之后,当我添加文本字段时,我运行了该应用程序,发现该应用程序为空.这是我的代码:import'package:flutter/material.dart';voidmain(){runApp(newMaterialApp(home:newMyApp(),));}clas

我在制作一个Flutter应用程序时,其中有一个文本,并且可以正常工作,但是之后,当我添加文本字段时,我运行了该应用程序,发现该应用程序为空.

这是我的代码:

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;  }}@H_403_9@

解决方法:

那是因为行容器不知道您的TextFIEld小部件的大小

这是您得到的错误:

    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)@H_403_9@

为了解决该问题,请在您的TextfIEld的父容器中为其设置一个宽度,如下所示:

Container(        wIDth: 200.0,        child: new TextFIEld(          decoration: inputdecoration(              border: inputborder.none,              hintText: 'Please enter a search term'),        ),      ),@H_403_9@

但是它在屏幕上看起来很奇怪,因此您可以使用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                      ),                    ),                  ),                ],              ),            ),          );@H_403_9@

Flexible Widget

总结

以上是内存溢出为你收集整理的文本添加文本字段时,Flutter屏幕显示为空全部内容,希望文章能够帮你解决文本添加文本字段时,Flutter屏幕显示为空所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1092170.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存