The "alternative" example is actually the right way.

This commit is contained in:
venir.dev
2022-10-10 09:10:24 +02:00
parent 3419d111a5
commit b52b983a6c
68 changed files with 51 additions and 46 deletions

22
sync_router/lib/auth.dart Normal file
View File

@ -0,0 +1,22 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
class AuthNotifier extends StateNotifier<bool> {
AuthNotifier() : super(false);
/// This mocks a login attempt with email and password
Future<void> login(String email, String password) async {
state = await Future.delayed(
const Duration(milliseconds: 750),
() => true,
);
}
/// This mocks a logout action
Future<void> logout() async {
state = false; // No request is mocked here but I guess we could
}
}
final authProvider = StateNotifierProvider<AuthNotifier, bool>((ref) {
return AuthNotifier();
});