有抖动的堆栈

问题描述 投票:0回答:1

所以我试图创建一个屏幕,我通过了一半,但是每当我尝试在行中添加textfield时,我都会对重叠的图像做一半,但是当我尝试运行它时,它会抛出这样的错误,当我尝试添加文本字段时发生

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
An InputDecorator, which is typically created by a TextField, cannot have an unbounded width.
This happens when the parent widget does not provide a finite width constraint. For example, if the InputDecorator is contained by a Row, then its width must be constrained. An Expanded widget or a SizedBox can be used to constrain the width of the InputDecorator or the TextField that contains it.
'package:flutter/src/material/input_decorator.dart':
Failed assertion: line 926 pos 7: 'layoutConstraints.maxWidth < double.infinity'

这是我尝试构建的屏幕enter image description here

设计代码

 Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("Registration", style: TextStyle(color: Colors.black)),
        backgroundColor: Colors.orange,
      ),
      body: SingleChildScrollView(
        child: Stack(
          children: <Widget>[
            Container(
              child: Image.asset('assets/images/gym.png',
                  height: 150, width: double.infinity, fit: BoxFit.fitWidth),
            ),
            Padding(
              padding: EdgeInsets.only(top: 90, left: 20),
              child: CircleAvatar(
                backgroundImage: AssetImage("assets/images/user_avatar.png"),
                radius: 55.0,
              ),
            ),
            Row(
              children: <Widget>[
                TextField(
                  decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: 'USer'),
                ),

                TextField(
                  decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: 'Mo'),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
flutter flutter-layout
1个回答
0
投票

发生这种情况是因为TextField需要整个屏幕的宽度,为避免出现这种情况,您可以将其包装在Expanded小部件内。

  Expanded(
        child: TextField(
          decoration:
              InputDecoration(border: InputBorder.none, hintText: 'USer'),
        ),
      ),
      Expanded(
        child: TextField(
          decoration:
              InputDecoration(border: InputBorder.none, hintText: 'Mo'),
        ),
      ),
© www.soinside.com 2019 - 2024. All rights reserved.