Browse Source

Merge pull request #426 from Leptopoda/cleanup/neon_exception

neon: cleanup NeonException
pull/421/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
9a0feef032
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 137
      packages/neon/neon/lib/src/widgets/exception.dart

137
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,80 +33,71 @@ 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,
); );
if (onlyIcon) { final message =
return Semantics( details.isUnauthorized ? AppLocalizations.of(context).loginAgain : AppLocalizations.of(context).actionRetry;
tooltip: details.text,
child: IconButton( final onPressed = details.isUnauthorized ? () => _openLoginPage(context) : onRetry;
icon: errorIcon,
padding: EdgeInsets.zero, if (onlyIcon) {
visualDensity: const VisualDensity( return Semantics(
horizontal: VisualDensity.minimumDensity, tooltip: details.text,
vertical: VisualDensity.minimumDensity, child: IconButton(
), icon: errorIcon,
tooltip: details.isUnauthorized padding: EdgeInsets.zero,
? AppLocalizations.of(context).loginAgain visualDensity: const VisualDensity(
: AppLocalizations.of(context).actionRetry, horizontal: VisualDensity.minimumDensity,
onPressed: () async { vertical: VisualDensity.minimumDensity,
if (details.isUnauthorized) { ),
_openLoginPage(context); tooltip: message,
} else { onPressed: onPressed,
onRetry(); ),
} );
}, }
),
); return Padding(
} padding: const EdgeInsets.all(5),
child: Column(
return Column( mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, children: [
children: [ Row(
Row( mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, children: [
children: [ errorIcon,
errorIcon, const SizedBox(
const SizedBox( width: 10,
width: 10, ),
), Flexible(
Flexible( child: Text(
child: Text( details.text,
details.text, style: TextStyle(
style: TextStyle( color: color,
color: color ?? Colors.red,
),
),
),
],
), ),
if (details.isUnauthorized) ...[ ),
ElevatedButton( ),
onPressed: () async => _openLoginPage(context), ],
child: Text(AppLocalizations.of(context).loginAgain),
),
] else ...[
ElevatedButton(
onPressed: onRetry,
child: Text(AppLocalizations.of(context).actionRetry),
),
],
],
);
},
), ),
); ElevatedButton(
onPressed: onPressed,
child: Text(message),
),
],
),
);
}
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