Стек с флаттером - PullRequest
       16

Стек с флаттером

0 голосов
/ 02 мая 2020

Итак, я пытаюсь создать экран, я прошел половину пути, но всякий раз, когда я пытаюсь добавить текстовое поле со строкой, я делаю половину с перекрывающимися изображениями, но когда я пытаюсь запустить его, он выдает такую ​​ошибку, это происходит, когда я пытаюсь добавить текстовое поле

════════ 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'

код для дизайна

 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'),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }

1 Ответ

1 голос
/ 02 мая 2020

Это происходит потому, что TextField требует ширину всего экрана, чтобы избежать этого, вы можете обернуть его внутри расширенного виджета.

 SingleChildScrollView(
    child: Stack(
      children: [
        Column(
          children: [
            Container(
              child: Image.asset('assets/images/crown.png',
                  height: 150,
                  width: double.infinity,
                  fit: BoxFit.fitWidth),
            ),
            SizedBox(
              height: 50,
            ),
            Row(
              children: <Widget>[
                Expanded(
                  child: TextField(
                    decoration: InputDecoration(
                        border: InputBorder.none, hintText: 'USer'),
                  ),
                ),
                Expanded(
                  child: TextField(
                    decoration: InputDecoration(
                        border: InputBorder.none, hintText: 'Mo'),
                  ),
                ),
              ],
            ),
          ],
        ),
        Padding(
          padding: EdgeInsets.only(top: 90, left: 20),
          child: CircleAvatar(
            backgroundImage: AssetImage("assets/images/crown.png"),
            radius: 55.0,
          ),
        ),
      ],
    ),
  ),
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...