30 lines
856 B
Dart

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<MyRandom> 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<String, dynamic>;
// Finally, we convert the Map into an Activity instance.
return MyRandom.fromJson(json);
}
@riverpod
class randomNotif extends _$randomNotif {
@override
Future<MyRandom> build() async{
return fetchData();
}
Future<void> again() async {
state = const AsyncLoading();
// ref.invalidateSelf();
ref.invalidateSelf();
}
}