Help The return type ‘Future’ isn’t a ‘Widget’,
Future deleteProduct(String productId) async {
String url = 'http://127.0.0.1:8000/api/products' + productId;
var response = await http.delete(Uri.parse(url));
return json.decode(response.body);
}
Code structure
GestureDetector(
onTap: () {
final snackBar = SnackBar(
content: const Text('Data berhasil Dihapus'));
Navigator.push( context,
MaterialPageRoute(
builder: (context) =>deleteProduct((snapshot.dataas dynamic)['data'][index]['id'].toString()).then((value) {setState(() {});
ScaffoldMessenger.of(context) .showSnackBar( snackBar);
})));
Need Help Thanks.
Error "The return type 'Future<Null>' isn't a 'Widget', as required by the closure's context."
2
Answers
You have to use your future
Function
inonTap
and then useshowSnackbar
.Example.
Change your
Future
function to includereturn type
ofMap<String, dynamic>
And use
FutureBuilder
in thebuilder
like: