I have this function
Future updateMember(Member member) async {
final User? user = Auth().currentUser;
final docMember =
FirebaseFirestore.instance.collection('users').doc(user?.uid);
member.id = docMember.id;
final json = member.toJson();
final response = await docMember
.update(json)
.then((value) => {print("done")})
.catchError((e) => (e));
return response;
}
Then I want to catch the error here and success message here
final response = updateMember(member);
if (response.then((value) => 'done') == true) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('success'),
backgroundColor: Colors.green,
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(catchError(onError)),
backgroundColor: Colors.red,
),
);
}
Please I need help on how I can implement this
This solves the problem
updateMember(member)
.whenComplete(
() => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('succes'),
backgroundColor: Colors.green,
),
))
.onError((error, stackTrace) =>
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(error.toString()),
backgroundColor: Colors.red,
),
));
});