import 'dart:convert'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:riverpod_flutter_tuts/outerapi/auth/model/my_random.dart'; import 'package:http/http.dart' as http; part 'random.g.dart'; Future fetchData() async { var ur = Uri.http('127.0.0.1:3000', '/p/random'); final response = await http.get(ur); // Using dart:convert, we then decode the JSON payload into a Map data structure. final json = jsonDecode(response.body) as Map; // Finally, we convert the Map into an Activity instance. return MyRandom.fromJson(json); } @riverpod class randomNotif extends _$randomNotif { @override Future build() async{ return fetchData(); } Future again() async { state = const AsyncLoading(); // ref.invalidateSelf(); ref.invalidateSelf(); } }