我对颤动甚至编码都是全新的,所以请帮助我并简单地说这是我的模型类
import 'dart:convert';
class LoginUserDataModel {
LoginUserDataModel({
required this.id,
required this.name,
required this.email,
required this.phoneNumber,
required this.password,
required this.address,
});
String id;
String name;
String email;
String phoneNumber;
String password;
String address;
factory LoginUserDataModel.fromJson(Map<String, dynamic> json) =>
LoginUserDataModel(
id: json["id"],
name: json["name"],
email: json["email"],
phoneNumber: json["phone_number"],
password: json["password"],
address: json["address"],
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"email": email,
"phone_number": phoneNumber,
"password": password,
"address": address,
};
}
我将 phone_number 发布到 php,实习生给了我具有该变量的行,然后我使用模型类。我可以在打印时看到 json 数据,但我想将单个值保存在变量中,以便以后使用
这是我的发布请求,我将电话号码发布到 php,这给了我包含该电话号码的行
Future loginWithMobile(String isoCode, String mobileNumber) async {
var url = 'http://192.168.1.5/server/login.php';
var data = {
"phone_number": mobileNumber,
};
http.Response res = await http.post(Uri.parse(url), body: data);
var details = json.decode(json.encode(res.body));
}