我正在使用Postman创建一个“创建帐户”页面。该页面包含文本字段“电子邮件,密码,名字,姓氏”。我已经创建了远程服务和产品控制器。并在创建帐户页面上调用该控制器。
如何为账户创建页面上的每个字段创建一个控制器。如何调用上面创建的方法的控制器?
产品控制器代码:
Future createaccount(email, password, firstname, lastname) async {
dio.Response? response = await remoteServices.createaccount(email, password, firstname, lastname);
if (response!.statusCode == 200) {
}
}
远程服务代码:
Future<Response?> createaccount(email, password, firstname, lastname) async {
var uri = '$_url/create-customer';
print(uri);
try {
final response = await dio.post(uri,data: {'email': email, 'password':password,'firstname':firstname, 'lastname':lastname});
print(response);
return response;
} on DioError catch (e) {
debugPrint(e.response!.data.toString());
return e.response!.data;
}
}
创建帐户代码:
ProductController productController = Get.find();
createAccount(){
}
.....
Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 35),
child: Container(
width: 310,
child: TextField(
decoration: InputDecoration(
label: RichText(
text: TextSpan(
text: 'First Name',
style: GoogleFonts.poppins(
color: Color(0xffc1c1c1),
fontSize: 17,
letterSpacing: 0.4),
children: const [
TextSpan(
text: ' *',
style: TextStyle(
color: Colors.red,
fontSize: 21,
)),
]),
),
),
onSubmitted: (Value){
},
),
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: Container(
width: 310,
child: TextField(
decoration: InputDecoration(
label: RichText(
text: TextSpan(
text: 'Last Name',
style: GoogleFonts.poppins(
color: Color(0xffc1c1c1),
fontSize: 17,
letterSpacing: 0.4),
children: const [
TextSpan(
text: ' *',
style: TextStyle(
color: Colors.red,
fontSize: 21,
)),
]),
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: Container(
width: 310,
child: TextField(
decoration: InputDecoration(
label: RichText(
text: TextSpan(
text: 'Enter Your Email',
style: GoogleFonts.poppins(
color: Color(0xffc1c1c1),
fontSize: 17,
letterSpacing: 0.4),
children: const [
TextSpan(
text: ' *',
style: TextStyle(
color: Colors.red,
fontSize: 21,
)),
]),
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: Container(
width: 310,
child: TextField(
obscureText: true,
decoration: InputDecoration(
label: RichText(
text: TextSpan(
text: 'Enter Your Password',
style: GoogleFonts.poppins(
color: Color(0xffc1c1c1),
fontSize: 17,
letterSpacing: 0.4),
children: const [
TextSpan(
text: ' *',
style: TextStyle(
color: Colors.red,
fontSize: 21,
)),
]),
),
suffixIcon: Icon(CupertinoIcons.eye_slash_fill, size: 25),
),
),
),
),
1条答案
按热度按时间cczfrluj1#
它很简单,你需要为每个字段定义
TextEditingController
,然后传递给它们,并使用它们为你的字段定义控制器,因为你需要一个控制器你定义的每个控制器都有一个名为
text
的参数,它可以给予你访问用户在字段中输入的值,你可以用它们把它们传递给服务器或..