I have an issue with creating POST request. No matter what I input, I keep getting null as email and password.
class _LoginPageState extends State<LoginPage> {
late LoginRequestModel requestModel;
@override
void initState() {
super.initState();
requestModel = LoginRequestModel();
}
I have two TextFormFields where I added
onSaved: (input) => requestModel.email = input
Then whenever when input values and I submit on my button it keeps printing {email: null, password: null }
print(requestModel.email); //null
import 'package:flutter/foundation.dart';
class LoginRequestModel {
String? email;
String? password;
LoginRequestModel({ this.email, this.password} );
factory LoginRequestModel.fromJson(Map<String, dynamic> json) {
return LoginRequestModel(
email: json['email'],
password: json['password']
);
}
}
class Auth {
static String baseUrl = "MY_API";
var client = http.Client();
void login(LoginRequestModel model) async {
await client.post(Uri.parse(baseUrl), body: model);
}
}
TextFormField(
cursorColor: Colors.black,
obscureText: false,
onSaved: (input) => requestModel.email = input,
How do I successfully make a POST request?

