feat(authentication): add custom routine, and documentation

This commit is contained in:
2023-04-13 23:24:11 +02:00
parent eafe4dc7c6
commit 3faceeebb6
19 changed files with 331 additions and 424 deletions
@@ -30,19 +30,6 @@ import 'package:go_router/go_router.dart';
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
// FutureOrResult<int?> onAccountChanges(
// AuthenticationRepository<int> repo,
// AuthChangeEvent? authEvent,
// ) async {
// final id = Random().nextInt(1000);
// final token =
// await repo.getIdentityToken().fold((value) => value, (error) => 'null');
// debugPrint(
// 'onAccountChanges: ${authEvent?.account}, type: ${authEvent.runtimeType}, token: $token, generatedId: $id');
// return Ok<int, AppException>(id);
// }
class App extends StatelessWidget {
final AuthenticationRepository<int> authenticationRepository =
AuthenticationRepositoryImpl(
@@ -64,7 +51,9 @@ class App extends StatelessWidget {
Widget build(BuildContext context) {
AuthenticationState<int>? previous;
final AuthenticationCubit<int> authenticationCubit = ExampleAuthenticationCubit(authenticationRepository: authenticationRepository);
final AuthenticationCubit<int> authenticationCubit =
ExampleAuthenticationCubit(
authenticationRepository: authenticationRepository);
final GoRouter router = GoRouter(
initialLocation: '/',
@@ -91,7 +80,7 @@ class App extends StatelessWidget {
return '/home';
}
}
return null;
return state.name;
},
);
@@ -49,4 +49,11 @@ class ExampleAuthenticationCubit extends AuthenticationCubit<int> {
return const Ok(null);
}
@override
FutureOrResult<void> onDelete() {
print('onDelete');
return const Ok(null);
}
}
@@ -35,14 +35,20 @@ class SubPage extends StatelessWidget {
icon: const Icon(Icons.logout_rounded)),
IconButton(
onPressed: () =>
context.read<AuthenticationRepository<int>>().refresh(),
context.read<AuthenticationCubit<int>>().refresh(),
icon: const Icon(Icons.refresh))
],
),
body: const Padding(
padding: EdgeInsets.all(8),
child: SingleChildScrollView(
child: Text('Another page'),
body: Padding(
padding: const EdgeInsets.all(8),
child: ListView(
children: [
const Text('Another page'),
ElevatedButton(
onPressed: () => context.read<AuthenticationCubit<int>>().delete(),
child: const Text('Delete account'),
),
],
),
),
);