Skip to content

Commit

Permalink
chore: review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dtscalac committed Oct 16, 2024
1 parent b0c09d4 commit 3f62129
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 77 deletions.
4 changes: 2 additions & 2 deletions catalyst_voices/lib/common/error_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ mixin ErrorHandlerStateMixin<E extends ErrorEmitter, T extends StatefulWidget>
@override
void handleError(Object error) {
if (error is LocalizedException) {
_handleLocalizedException(error);
handleLocalizedException(error);
}
}

void _handleLocalizedException(LocalizedException exception) {
void handleLocalizedException(LocalizedException exception) {
VoicesSnackBar(
type: VoicesSnackBarType.error,
message: exception.message(context),
Expand Down
114 changes: 64 additions & 50 deletions catalyst_voices/lib/pages/account/unlock_keychain_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

/// A dialog which allows to unlock the session (keychain).
class UnlockKeychainDialog extends StatelessWidget {
class UnlockKeychainDialog extends StatefulWidget {
const UnlockKeychainDialog({super.key});

@override
Widget build(BuildContext context) {
return VoicesTwoPaneDialog(
left: InformationPanel(
title: context.l10n.unlockDialogHeader,
picture: const UnlockKeychainPicture(),
),
right: const _UnlockPasswordPanel(),
);
}

static Future<void> show(BuildContext context) {
return VoicesDialog.show(
context: context,
Expand All @@ -36,17 +25,13 @@ class UnlockKeychainDialog extends StatelessWidget {
barrierDismissible: false,
);
}
}

class _UnlockPasswordPanel extends StatefulWidget {
const _UnlockPasswordPanel();

@override
State<_UnlockPasswordPanel> createState() => _UnlockPasswordPanelState();
State<UnlockKeychainDialog> createState() => _UnlockKeychainDialogState();
}

class _UnlockPasswordPanelState extends State<_UnlockPasswordPanel>
with ErrorHandlerStateMixin<SessionBloc, _UnlockPasswordPanel> {
class _UnlockKeychainDialogState extends State<UnlockKeychainDialog>
with ErrorHandlerStateMixin<SessionBloc, UnlockKeychainDialog> {
final TextEditingController _passwordController = TextEditingController();
LocalizedException? _error;

Expand All @@ -68,41 +53,35 @@ class _UnlockPasswordPanelState extends State<_UnlockPasswordPanel>
@override
Widget build(BuildContext context) {
return BlocListener<SessionBloc, SessionState>(
listener: (context, state) {
if (state is ActiveUserSessionState) {
VoicesSnackBar(
type: VoicesSnackBarType.success,
behavior: SnackBarBehavior.floating,
icon: VoicesAssets.icons.lockOpen.buildIcon(),
title: context.l10n.unlockSnackbarTitle,
message: context.l10n.unlockSnackbarMessage,
).show(context);

Navigator.of(context).pop();
}
},
child: 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: _passwordController,
error: _error,
),
const Spacer(),
_Navigation(
onUnlock: _onUnlock,
),
],
listener: _handleStateChange,
child: VoicesTwoPaneDialog(
left: InformationPanel(
title: context.l10n.unlockDialogHeader,
picture: const UnlockKeychainPicture(),
),
right: _UnlockPasswordPanel(
controller: _passwordController,
error: _error,
onUnlock: _onUnlock,
),
),
);
}

void _handleStateChange(BuildContext context, SessionState state) {
if (state is ActiveUserSessionState) {
VoicesSnackBar(
type: VoicesSnackBarType.success,
behavior: SnackBarBehavior.floating,
icon: VoicesAssets.icons.lockOpen.buildIcon(),
title: context.l10n.unlockSnackbarTitle,
message: context.l10n.unlockSnackbarMessage,
).show(context);

Navigator.of(context).pop();
}
}

void _onUnlock() {
setState(() {
_error = null;
Expand All @@ -116,6 +95,41 @@ class _UnlockPasswordPanelState extends State<_UnlockPasswordPanel>
}
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ class UnlockKeychainPicture extends StatelessWidget {
Widget build(BuildContext context) {
return TaskPicture(
child: TaskPictureIconBox(
child: DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).colors.elevationsOnSurfaceNeutralLv0,
borderRadius: BorderRadius.circular(8),
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),
),
),
),
),
Expand Down
37 changes: 16 additions & 21 deletions catalyst_voices/lib/widgets/snackbar/voices_snackbar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:math';

import 'package:catalyst_voices/widgets/common/affix_decorator.dart';
import 'package:catalyst_voices/widgets/snackbar/voices_snackbar_action.dart';
import 'package:catalyst_voices/widgets/snackbar/voices_snackbar_type.dart';
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
Expand Down Expand Up @@ -171,29 +172,23 @@ class _IconAndTitle extends StatelessWidget {
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;

return Row(
mainAxisSize: MainAxisSize.min,
children: [
IconTheme(
data: IconThemeData(
size: 20,
color: type.iconColor(context),
),
child: icon,
return AffixDecorator(
prefix: IconTheme(
data: IconThemeData(
size: 20,
color: type.iconColor(context),
),
const SizedBox(width: 8),
Flexible(
child: Text(
title,
style: TextStyle(
color: type.titleColor(context),
fontSize: textTheme.titleMedium?.fontSize,
fontWeight: textTheme.titleMedium?.fontWeight,
fontFamily: textTheme.titleMedium?.fontFamily,
),
),
child: icon,
),
child: Text(
title,
style: TextStyle(
color: type.titleColor(context),
fontSize: textTheme.titleMedium?.fontSize,
fontWeight: textTheme.titleMedium?.fontWeight,
fontFamily: textTheme.titleMedium?.fontFamily,
),
],
),
);
}
}

0 comments on commit 3f62129

Please sign in to comment.