Виджеты флаттера не отображаются - PullRequest
0 голосов
/ 14 мая 2018

Следующая компоновка Flutter (две строки внутри столбца, каждая строка содержит текстовый виджет и виджет поля) компилируется и запускается, но виджеты с текстовым и текстовым полями не отображаются.То, что вы должны увидеть, это слово «имя пользователя», за которым следует текстовое поле в одной строке, а за словом «пароль» следует текстовое поле в следующей строке.Что я делаю не так, пожалуйста?

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return new MaterialApp(
     title: 'Welcome to Flutter',
     home: new Scaffold(
         appBar: new AppBar(
           title: new Text('Welcome to Flutter'),
         ),
         body: new Container(
           padding: new EdgeInsets.all(20.0),
           child: new Column(
             crossAxisAlignment: CrossAxisAlignment.start,
             children: [
               new Row(
                 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                 children: [
                   new Text('User Name'),
                   new TextField(
                     autofocus: true,
                     decoration: new InputDecoration(
                         border: InputBorder.none,
                         hintText: 'Please enter your user name'),
                   ),
                 ],
               ),
               new Row(
                 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                 children: [
                   new Text('User Name'),
                   new TextField(
                     decoration: new InputDecoration(
                         border: InputBorder.none,
                         hintText: 'Please enter your pasword'),
                   ),
                 ],
               ),
             ],
           ),
         )),
   );
 }
}

1 Ответ

0 голосов
/ 01 июня 2018

Per https://stackoverflow.com/a/45990477/1649135 если вы помещаете виджеты, которые не имеют внутренней ширины в строке, вы должны вкладывать их в гибкий виджет.

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Welcome to Flutter',
      home: new Scaffold(
          appBar: new AppBar(
            title: new Text('Welcome to Flutter'),
          ),
          body: new Container(
            padding: new EdgeInsets.all(20.0),
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                new Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    new Flexible(
                      child: new Text('User Name:'),
                    ),
                    new Flexible(
                      child: new Container(
                        margin: const EdgeInsets.all(15.0),
                        padding: const EdgeInsets.all(3.0),
                        decoration: new BoxDecoration(
                            border: new Border.all(color: Colors.blueAccent)),
                        child: new TextField(
                          style: Theme.of(context).textTheme.body1,
                        ),
                      ),
                    ),
                  ],
                ),
                new Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    new Flexible(
                      child: new Text('Password:'),
                    ),
                    new Flexible(
                      child: new Container(
                        margin: const EdgeInsets.all(15.0),
                        padding: const EdgeInsets.all(3.0),
                        decoration: new BoxDecoration(
                            border: new Border.all(color: Colors.blueAccent)),
                        child: new TextField(
                          style: Theme.of(context).textTheme.body1,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          )),
    );
  }
}
...