-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into adr/api_endpoints
- Loading branch information
Showing
24 changed files
with
774 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'package:catalyst_voices/widgets/snackbar/voices_snackbar.dart'; | ||
import 'package:catalyst_voices/widgets/snackbar/voices_snackbar_type.dart'; | ||
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart'; | ||
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart'; | ||
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
/// Listens globally to a session and can show different | ||
/// snackBars when a session changes. | ||
class GlobalSessionListener extends StatelessWidget { | ||
final Widget child; | ||
|
||
const GlobalSessionListener({ | ||
super.key, | ||
required this.child, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocListener<SessionBloc, SessionState>( | ||
listenWhen: _listenToSessionChangesWhen, | ||
listener: _onSessionChanged, | ||
child: child, | ||
); | ||
} | ||
|
||
bool _listenToSessionChangesWhen(SessionState prev, SessionState next) { | ||
// We deliberately check if previous was guest because we don't | ||
// want to show the snackbar after the registration is completed. | ||
final keychainUnlocked = | ||
prev is GuestSessionState && next is ActiveUserSessionState; | ||
|
||
final keychainLocked = | ||
prev is ActiveUserSessionState && next is GuestSessionState; | ||
|
||
return keychainUnlocked || keychainLocked; | ||
} | ||
|
||
void _onSessionChanged(BuildContext context, SessionState state) { | ||
if (state is ActiveUserSessionState) { | ||
_onUnlockedKeychain(context); | ||
} else if (state is GuestSessionState) { | ||
_onLockedKeychain(context); | ||
} | ||
} | ||
|
||
void _onUnlockedKeychain(BuildContext context) { | ||
VoicesSnackBar( | ||
type: VoicesSnackBarType.success, | ||
behavior: SnackBarBehavior.floating, | ||
icon: VoicesAssets.icons.lockOpen.buildIcon(), | ||
title: context.l10n.unlockSnackbarTitle, | ||
message: context.l10n.unlockSnackbarMessage, | ||
).show(context); | ||
} | ||
|
||
void _onLockedKeychain(BuildContext context) { | ||
VoicesSnackBar( | ||
type: VoicesSnackBarType.error, | ||
behavior: SnackBarBehavior.floating, | ||
icon: VoicesAssets.icons.lockClosed.buildIcon(), | ||
title: context.l10n.lockSnackbarTitle, | ||
message: context.l10n.lockSnackbarMessage, | ||
).show(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
catalyst_voices/lib/pages/account/unlock_keychain_dialog.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import 'package:catalyst_voices/common/error_handler.dart'; | ||
import 'package:catalyst_voices/pages/registration/pictures/unlock_keychain_picture.dart'; | ||
import 'package:catalyst_voices/pages/registration/widgets/information_panel.dart'; | ||
import 'package:catalyst_voices/pages/registration/widgets/registration_stage_message.dart'; | ||
import 'package:catalyst_voices/widgets/widgets.dart'; | ||
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart'; | ||
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; | ||
import 'package:catalyst_voices_services/catalyst_voices_services.dart'; | ||
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
/// A dialog which allows to unlock the session (keychain). | ||
class UnlockKeychainDialog extends StatefulWidget { | ||
const UnlockKeychainDialog({super.key}); | ||
|
||
static Future<void> show(BuildContext context) { | ||
return VoicesDialog.show( | ||
context: context, | ||
routeSettings: const RouteSettings(name: '/unlock'), | ||
builder: (context) => const UnlockKeychainDialog(), | ||
barrierDismissible: false, | ||
); | ||
} | ||
|
||
@override | ||
State<UnlockKeychainDialog> createState() => _UnlockKeychainDialogState(); | ||
} | ||
|
||
class _UnlockKeychainDialogState extends State<UnlockKeychainDialog> | ||
with ErrorHandlerStateMixin<SessionBloc, UnlockKeychainDialog> { | ||
final TextEditingController _passwordController = TextEditingController(); | ||
LocalizedException? _error; | ||
|
||
@override | ||
void dispose() { | ||
_passwordController.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
void handleError(Object error) { | ||
setState(() { | ||
_error = error is LocalizedException | ||
? error | ||
: const LocalizedUnlockPasswordException(); | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocListener<SessionBloc, SessionState>( | ||
listener: _handleSessionChange, | ||
child: VoicesTwoPaneDialog( | ||
left: InformationPanel( | ||
title: context.l10n.unlockDialogHeader, | ||
picture: const UnlockKeychainPicture(), | ||
), | ||
right: _UnlockPasswordPanel( | ||
controller: _passwordController, | ||
error: _error, | ||
onUnlock: _onUnlock, | ||
), | ||
), | ||
); | ||
} | ||
|
||
void _handleSessionChange(BuildContext context, SessionState state) { | ||
if (state is ActiveUserSessionState) { | ||
Navigator.of(context).pop(); | ||
} | ||
} | ||
|
||
void _onUnlock() { | ||
setState(() { | ||
_error = null; | ||
}); | ||
|
||
final password = _passwordController.text; | ||
final unlockFactor = PasswordLockFactor(password); | ||
context | ||
.read<SessionBloc>() | ||
.add(UnlockSessionEvent(unlockFactor: unlockFactor)); | ||
} | ||
} | ||
|
||
class _UnlockPasswordPanel extends StatelessWidget { | ||
final TextEditingController controller; | ||
final LocalizedException? error; | ||
final VoidCallback onUnlock; | ||
|
||
const _UnlockPasswordPanel({ | ||
required this.controller, | ||
required this.error, | ||
required this.onUnlock, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
const SizedBox(height: 24), | ||
RegistrationStageMessage( | ||
title: Text(context.l10n.unlockDialogTitle), | ||
subtitle: Text(context.l10n.unlockDialogContent), | ||
), | ||
const SizedBox(height: 24), | ||
_UnlockPassword( | ||
controller: controller, | ||
error: error, | ||
), | ||
const Spacer(), | ||
_Navigation( | ||
onUnlock: onUnlock, | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class _UnlockPassword extends StatelessWidget { | ||
final TextEditingController controller; | ||
final LocalizedException? error; | ||
|
||
const _UnlockPassword({ | ||
required this.controller, | ||
required this.error, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return VoicesPasswordTextField( | ||
controller: controller, | ||
decoration: VoicesTextFieldDecoration( | ||
labelText: context.l10n.unlockDialogHint, | ||
errorText: error?.message(context), | ||
hintText: context.l10n.passwordLabelText, | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _Navigation extends StatelessWidget { | ||
final VoidCallback onUnlock; | ||
|
||
const _Navigation({ | ||
required this.onUnlock, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Row( | ||
children: [ | ||
Expanded( | ||
child: VoicesOutlinedButton( | ||
onTap: () => Navigator.of(context).pop(), | ||
child: Text(context.l10n.continueAsGuest), | ||
), | ||
), | ||
const SizedBox(width: 10), | ||
Expanded( | ||
child: VoicesFilledButton( | ||
onTap: onUnlock, | ||
child: Text(context.l10n.confirmPassword), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
catalyst_voices/lib/pages/registration/pictures/unlock_keychain_picture.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:catalyst_voices/pages/registration/pictures/task_picture.dart'; | ||
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class UnlockKeychainPicture extends StatelessWidget { | ||
const UnlockKeychainPicture({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return TaskPicture( | ||
child: TaskPictureIconBox( | ||
child: AspectRatio( | ||
aspectRatio: 101 / 42, | ||
child: Container( | ||
height: double.infinity, | ||
margin: const EdgeInsets.all(10), | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).colors.elevationsOnSurfaceNeutralLv0, | ||
borderRadius: BorderRadius.circular(8), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.