当我想在代码中添加文本表单字段时,我遇到了一些错误,提示“位置参数必须出现在命名参数之前”和“位置参数太多”,设计将类似于 this
我需要将文本表单字段放在文本下方,如何添加文本表单字段而不出现任何错误?
这是我的代码
import 'package:flutter/material.dart';
class ForgotPassword extends StatefulWidget {
const ForgotPassword({Key? key}) : super(key: key);
@override
_ForgotPasswordState createState() => _ForgotPasswordState();
}
class _ForgotPasswordState extends State<ForgotPassword> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(onPressed: () {}, icon: Icon(Icons.exit_to_app)),
),
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(
vertical: 35.0,
),
child: Text(
'Forgot Password',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 12, 0, 0),
child: Container(
child: Image.asset('assets/forgot password 1.png'),
),
),
new Container(
height: 440.0,
color: Colors.transparent,
child: Container(
decoration: new BoxDecoration(
color: Colors.blue,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(40.0),
topRight: const Radius.circular(40.0),
)),
child: new Align(
alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 40),
child: Text(
'Masukkan Email',
style: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.bold),
),
sizedBox(height: 20,)
),
),
),
),
],
),
),
),
);
}
}
最佳答案
将类的名称更改为您的类名,我在名称下方创建了 TextFormField
import 'package:flutter/material.dart';
class TabScreen extends StatefulWidget {
const TabScreen({Key? key}) : super(key: key);
@override
_TabScreenState createState() => _TabScreenState();
}
class _TabScreenState extends State<TabScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(onPressed: () {}, icon: Icon(Icons.exit_to_app)),
),
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Column(
children: [
Padding(
padding: EdgeInsets.symmetric(
vertical: 35.0,
),
child: Text(
'Forgot Password',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 12, 0, 0),
child: Container(
child: Icon(Icons.exit_to_app),
),
),
],
),
Container(
height: 440.0,
color: Colors.transparent,
child: Container(
decoration: new BoxDecoration(
color: Colors.blue,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(40.0),
topRight: const Radius.circular(40.0),
)),
child: new Align(
alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 40),
child: Column(
children: [
Text(
'Masukkan Email',
style: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.bold),
),
Container(
margin: EdgeInsets.all(15),
child: TextFormField(showCursor: true, cursorColor: Colors.white,
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.w600,
),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
focusColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide:
const BorderSide(color: Colors.black, width: 1.0),
borderRadius: BorderRadius.circular(10.0),
),
// fillColor: Colors.grey,
hintText: "Email",
),
),
),
],
),
// sizedBox(height: 20,)
),
),
),
)
],
),
),
),
);
}
}
关于android - 位置参数必须出现在命名参数之前,并且 flutter 上的位置参数太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69341032/