I am working with flutter for an app and I need to get some data already saved.
I am wanting to obtain the id from the database and I am getting the following problem.
If they would know any way to transform so that I can get the data.
Console:
lib/screens/profile.dart:49:40: Error: A value of type 'Object' can't be assigned to a variable of type 'String'.
- 'Object' is from 'dart:core'.
txtIdController.text =user!.id ??'';
profile.dart
User? user;
bool loading = true;
GlobalKey<FormState> formKey = GlobalKey<FormState>();
File? _imageFile;
final _picker = ImagePicker();
TextEditingController txtNameController = TextEditingController();
TextEditingController txtemailController = TextEditingController();
TextEditingController txtPhoneController = TextEditingController();
TextEditingController txtIdController = TextEditingController(); //El Id
// get user detail
void getUser() async {
ApiResponse response = await getUserDetail();
if (response.error == null) {
setState(() {
user = response.data as User;
loading = false;
txtNameController.text = user!.name ?? '';
txtemailController.text = user!.email ?? '';
txtPhoneController.text =user!.phone ??'';
txtIdController.text =user!.id ??''; //aca es donde salta el error
});
user.dart
class User { int? id;
String? name;
String? phone;
String? image;
String? email;
String? token;
User({
this.id,
this.name,
this.phone,
this.image,
this.email,
this.token
});
}
}