Browse Source

neon: cleanup NeonException

pull/426/head
Nikolas Rimikis 1 year ago
parent
commit
84b3046342
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 53
      packages/neon/neon/lib/src/widgets/exception.dart

53
packages/neon/neon/lib/src/widgets/exception.dart

@ -25,7 +25,7 @@ class NeonException extends StatelessWidget {
action: details.isUnauthorized action: details.isUnauthorized
? SnackBarAction( ? SnackBarAction(
label: AppLocalizations.of(context).loginAgain, label: AppLocalizations.of(context).loginAgain,
onPressed: () async => _openLoginPage(context), onPressed: () => _openLoginPage(context),
) )
: null, : null,
), ),
@ -33,20 +33,25 @@ class NeonException extends StatelessWidget {
} }
@override @override
Widget build(final BuildContext context) => exception == null Widget build(final BuildContext context) {
? Container() if (exception == null) {
: Container( return const SizedBox();
padding: !onlyIcon ? const EdgeInsets.all(5) : null, }
child: Builder(
builder: (final context) {
final details = _getExceptionDetails(context, exception); final details = _getExceptionDetails(context, exception);
final color = this.color ?? Theme.of(context).colorScheme.error;
final errorIcon = Icon( final errorIcon = Icon(
Icons.error_outline, Icons.error_outline,
size: iconSize ?? 30, size: iconSize ?? 30,
color: color ?? Colors.red, color: color,
); );
final message =
details.isUnauthorized ? AppLocalizations.of(context).loginAgain : AppLocalizations.of(context).actionRetry;
final onPressed = details.isUnauthorized ? () => _openLoginPage(context) : onRetry;
if (onlyIcon) { if (onlyIcon) {
return Semantics( return Semantics(
tooltip: details.text, tooltip: details.text,
@ -57,21 +62,15 @@ class NeonException extends StatelessWidget {
horizontal: VisualDensity.minimumDensity, horizontal: VisualDensity.minimumDensity,
vertical: VisualDensity.minimumDensity, vertical: VisualDensity.minimumDensity,
), ),
tooltip: details.isUnauthorized tooltip: message,
? AppLocalizations.of(context).loginAgain onPressed: onPressed,
: AppLocalizations.of(context).actionRetry,
onPressed: () async {
if (details.isUnauthorized) {
_openLoginPage(context);
} else {
onRetry();
}
},
), ),
); );
} }
return Column( return Padding(
padding: const EdgeInsets.all(5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Row( Row(
@ -85,28 +84,20 @@ class NeonException extends StatelessWidget {
child: Text( child: Text(
details.text, details.text,
style: TextStyle( style: TextStyle(
color: color ?? Colors.red, color: color,
), ),
), ),
), ),
], ],
), ),
if (details.isUnauthorized) ...[
ElevatedButton( ElevatedButton(
onPressed: () async => _openLoginPage(context), onPressed: onPressed,
child: Text(AppLocalizations.of(context).loginAgain), child: Text(message),
), ),
] else ...[
ElevatedButton(
onPressed: onRetry,
child: Text(AppLocalizations.of(context).actionRetry),
),
],
], ],
);
},
), ),
); );
}
static _ExceptionDetails _getExceptionDetails(final BuildContext context, final dynamic exception) { static _ExceptionDetails _getExceptionDetails(final BuildContext context, final dynamic exception) {
if (exception is String) { if (exception is String) {

Loading…
Cancel
Save