Node.js注册API在Thunder Client正常,集成Flutter后失效求助
Node.js注册API在Thunder Client正常但Flutter集成失败
我用Node.js开发了注册API,在Thunder Client中测试运行正常,但集成到Flutter项目后无法正常工作。此前使用类似的API和Flutter代码均无问题,但本次点击注册按钮时出现错误。
错误截图

Node.js API代码截图

Flutter API集成代码截图

Flutter注册页面完整代码
import 'package:flutter/material.dart'; import 'package:order_eats/APIS/user_api.dart'; import 'package:order_eats/screens/auth_screens/login.dart'; import 'package:order_eats/screens/auth_screens/widgets/custom_button.dart'; import 'package:order_eats/screens/auth_screens/widgets/custom_field.dart'; class SignUp extends StatefulWidget { const SignUp({super.key}); static const routeName = '/signup'; @override State<SignUp> createState() => _SignUpState(); } class _SignUpState extends State<SignUp> { final TextEditingController emailController = TextEditingController(); final TextEditingController passwordController = TextEditingController(); final TextEditingController nameController = TextEditingController(); final formKey = GlobalKey<FormState>(); void userSignup() { UserApis().userSignUP(context, emailController.text, passwordController.text, nameController.text); setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( body: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( padding: const EdgeInsets.all(10), child: Form( key: formKey, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( margin: const EdgeInsets.symmetric(horizontal: 20), child: const Text( 'Order Eats', style: TextStyle( fontSize: 25, fontWeight: FontWeight.w900, color: Color.fromRGBO(255, 97, 164, 1)), ), ), const SizedBox( height: 20, ), const Text( 'Lets get started', style: TextStyle( fontSize: 20, color: Colors.black, fontWeight: FontWeight.bold), ), const SizedBox( height: 20, ), CustomField(name: 'Name', controller: nameController), const SizedBox( height: 20, ), CustomField( name: 'Email', controller: emailController, ), const SizedBox( height: 20, ), CustomField(name: 'Password', controller: passwordController), const SizedBox( height: 20, ), CustomButton( ontap: () { if (formKey.currentState!.validate()) { userSignup(); } }, text: 'Sign Up'), const SizedBox( height: 20, ), ], ), ), ), Row( children: [ const Text( 'Already have an account? ', style: TextStyle( color: Colors.black, ), ), GestureDetector( onTap: () => Navigator.of(context).pushNamed(LoginScreen.routeName), child: const Text( 'Login', style: TextStyle( color: Color.fromRGBO(255, 97, 164, 1), fontWeight: FontWeight.bold), ), ) ], ) ], ), ); } }
内容的提问来源于stack exchange,提问作者Umair
相关产品推荐
相关产品推荐

