gpt4 book ai didi

flutter-layout - Flutter小部件未显示

转载 作者:行者123 更新时间:2023-12-03 15:21:59 26 4
gpt4 key购买 nike

以下Flutter布局(一列内有两行,每行包含一个文本小部件和一个字段小部件)可以编译并运行-但不会显示text和text字段小部件。您应该看到的是单词“username”和一行中的文本字段,以及单词“password”和下一行中的文本字段。请问我做错了什么?

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

最佳答案

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

关于flutter-layout - Flutter小部件未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50332040/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com