Browse Source

Merge pull request #426 from Leptopoda/cleanup/neon_exception

neon: cleanup NeonException
pull/421/head
Nikolas Rimikis 2 years 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
? SnackBarAction(
label: AppLocalizations.of(context).loginAgain,
onPressed: () async => _openLoginPage(context),
onPressed: () => _openLoginPage(context),
)
: null,
),
@ -33,80 +33,71 @@ class NeonException extends StatelessWidget {
}
@override
Widget build(final BuildContext context) => exception == null
? Container()
: Container(
padding: !onlyIcon ? const EdgeInsets.all(5) : null,
child: Builder(
builder: (final context) {
final details = _getExceptionDetails(context, exception);
final errorIcon = Icon(
Icons.error_outline,
size: iconSize ?? 30,
color: color ?? Colors.red,
);
if (onlyIcon) {
return Semantics(
tooltip: details.text,
child: IconButton(
icon: errorIcon,
padding: EdgeInsets.zero,
visualDensity: const VisualDensity(
horizontal: VisualDensity.minimumDensity,
vertical: VisualDensity.minimumDensity,
),
tooltip: details.isUnauthorized
? AppLocalizations.of(context).loginAgain
: AppLocalizations.of(context).actionRetry,
onPressed: () async {
if (details.isUnauthorized) {
_openLoginPage(context);
} else {
onRetry();
}
},
),
);
}
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
errorIcon,
const SizedBox(
width: 10,
),
Flexible(
child: Text(
details.text,
style: TextStyle(
color: color ?? Colors.red,
),
),
),
],
Widget build(final BuildContext context) {
if (exception == null) {
return const SizedBox();
}
final details = _getExceptionDetails(context, exception);
final color = this.color ?? Theme.of(context).colorScheme.error;
final errorIcon = Icon(
Icons.error_outline,
size: iconSize ?? 30,
color: color,
);
final message =
details.isUnauthorized ? AppLocalizations.of(context).loginAgain : AppLocalizations.of(context).actionRetry;
final onPressed = details.isUnauthorized ? () => _openLoginPage(context) : onRetry;
if (onlyIcon) {
return Semantics(
tooltip: details.text,
child: IconButton(
icon: errorIcon,
padding: EdgeInsets.zero,
visualDensity: const VisualDensity(
horizontal: VisualDensity.minimumDensity,
vertical: VisualDensity.minimumDensity,
),
tooltip: message,
onPressed: onPressed,
),
);
}
return Padding(
padding: const EdgeInsets.all(5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
errorIcon,
const SizedBox(
width: 10,
),
Flexible(
child: Text(
details.text,
style: TextStyle(
color: color,
),
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) {
if (exception is String) {

Loading…
Cancel
Save