gpt4 book ai didi

flutter - Flutter:列行[初学者]

转载 作者:行者123 更新时间:2023-12-03 05:00:06 26 4
gpt4 key购买 nike

我是Flutter的新手,此刻我尝试编写我的第一个App。
我只想用“文本字段”实现一个屏幕-可行。
现在,我想将前两个文本字段彼此相邻排列。我尝试使用Row(),但没有出现任何错误,但是突然模拟器显示了一个空白页。

有人可以告诉我我必须改变什么吗?我不知道我做错了什么,因为我没有收到任何错误。

感谢帮助!

import 'package:flutter/material.dart';

class TestEdit extends StatefulWidget {
@override
_TestEditState createState() => _TestEditState();
}

class _TestEditState extends State<TestEdit> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: true,
//`true` if you want Flutter to automatically add Back Button when needed,
//or `false` if you want to force your own back button every where
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.pop(context, false),
),
),
body: Column(
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
//mainAxisSize: MainAxisSize.min,
//padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
children: <Widget>[
//Row(children:[

//crossAxisAlignment: CrossAxisAlignment.start,
//mainAxisSize: MainAxisSize.min,
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'InputFirst',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'InputSecond',
),
),
),
],
),
//],
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
],
),
);
}
}

最佳答案

TextField小部件将尝试尽可能地水平扩展。

因此,如果要在TextField中放入Row,则应使用Flexible(或Expanded)小部件将其包装。

试试这个,

class TestEdit extends StatefulWidget {
@override
_TestEditState createState() => _TestEditState();
}

class _TestEditState extends State<TestEdit> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: true,
//`true` if you want Flutter to automatically add Back Button when needed,
//or `false` if you want to force your own back button every where
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.pop(context, false),
),
),
body: Column(
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
//mainAxisSize: MainAxisSize.min,
//padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
children: <Widget>[
//Row(children:[

//crossAxisAlignment: CrossAxisAlignment.start,
//mainAxisSize: MainAxisSize.min,
Expanded( //TODO: Wrap with `Expanded`
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'InputFirst',
),
),
),
),
Expanded( //TODO: Wrap with Expanded
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'InputSecond',
),
),
),
),
],
),
//],
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 10, 10, 0),
child: TextField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Input',
),
),
),
],
),
);
}
}

关于flutter - Flutter:列行[初学者],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59665060/

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