@ -28,11 +28,11 @@ class NeonError extends StatelessWidget {
final Color ? color ;
final Color ? color ;
static void showSnackbar ( final BuildContext context , final dynamic error ) {
static void showSnackbar ( final BuildContext context , final dynamic error ) {
final details = getDetails ( context , error ) ;
final details = getDetails ( error ) ;
ScaffoldMessenger . of ( context ) . showSnackBar (
ScaffoldMessenger . of ( context ) . showSnackBar (
SnackBar (
SnackBar (
content: Text ( details . text ) ,
content: Text ( details . getText ( con text) ) ,
action: details . isUnauthorized
action: details . isUnauthorized
? SnackBarAction (
? SnackBarAction (
label: AppLocalizations . of ( context ) . loginAgain ,
label: AppLocalizations . of ( context ) . loginAgain ,
@ -49,7 +49,7 @@ class NeonError extends StatelessWidget {
return const SizedBox ( ) ;
return const SizedBox ( ) ;
}
}
final details = getDetails ( context , error ) ;
final details = getDetails ( error ) ;
final color = this . color ? ? Theme . of ( context ) . colorScheme . error ;
final color = this . color ? ? Theme . of ( context ) . colorScheme . error ;
final errorIcon = Icon (
final errorIcon = Icon (
@ -65,7 +65,7 @@ class NeonError extends StatelessWidget {
if ( onlyIcon ) {
if ( onlyIcon ) {
return Semantics (
return Semantics (
tooltip: details . text ,
tooltip: details . getText ( con text) ,
child: IconButton (
child: IconButton (
icon: errorIcon ,
icon: errorIcon ,
padding: EdgeInsets . zero ,
padding: EdgeInsets . zero ,
@ -93,7 +93,7 @@ class NeonError extends StatelessWidget {
) ,
) ,
Flexible (
Flexible (
child: Text (
child: Text (
details . text ,
details . getText ( con text) ,
style: TextStyle (
style: TextStyle (
color: color ,
color: color ,
) ,
) ,
@ -111,78 +111,64 @@ class NeonError extends StatelessWidget {
}
}
@ internal
@ internal
static ExceptionDetails getDetails ( final BuildContext context , final dynamic error ) {
static Neon ExceptionDetails getDetails ( final dynamic error ) {
if ( error is String ) {
if ( error is String ) {
return ExceptionDetails (
return Neon ExceptionDetails(
text: error ,
ge tT ext: ( final _ ) = > error ,
) ;
) ;
}
}
if ( error is MissingPermissionException ) {
if ( error is NeonException ) {
return ExceptionDetails (
return error . details ;
text: AppLocalizations . of ( context ) . errorMissingPermission ( error . permission . toString ( ) . split ( ' . ' ) [ 1 ] ) ,
) ;
}
if ( error is UnableToOpenFileException ) {
return ExceptionDetails (
text: AppLocalizations . of ( context ) . errorUnableToOpenFile ,
) ;
}
if ( error is InvalidQRcodeException ) {
return ExceptionDetails (
text: AppLocalizations . of ( context ) . errorInvalidQRcode ,
) ;
}
}
if ( error is DynamiteApiException ) {
if ( error is DynamiteApiException ) {
if ( error . statusCode = = 401 ) {
if ( error . statusCode = = 401 ) {
return ExceptionDetails (
return NeonExceptionDetails (
text: AppLocalizations . of ( context ) . errorCredentialsForAccountNoLongerMatch ,
getText: ( final context ) = > AppLocalizations . of ( context ) . errorCredentialsForAccountNoLongerMatch ,
isUnauthorized: true ,
isUnauthorized: true ,
) ;
) ;
}
}
if ( error . statusCode > = 500 & & error . statusCode < = 599 ) {
if ( error . statusCode > = 500 & & error . statusCode < = 599 ) {
return ExceptionDetails (
return NeonExceptionDetails (
text: AppLocalizations . of ( context ) . errorServerHadAProblemProcessingYourRequest ,
getText: ( final context ) = > AppLocalizations . of ( context ) . errorServerHadAProblemProcessingYourRequest ,
) ;
) ;
}
}
}
}
if ( error is SocketException ) {
if ( error is SocketException ) {
return ExceptionDetails (
return Neon ExceptionDetails(
text: error . address ! = null
ge tT ext: ( final context ) = > error . address ! = null
? AppLocalizations . of ( context ) . errorUnableToReachServerAt ( error . address ! . host )
? AppLocalizations . of ( context ) . errorUnableToReachServerAt ( error . address ! . host )
: AppLocalizations . of ( context ) . errorUnableToReachServer ,
: AppLocalizations . of ( context ) . errorUnableToReachServer ,
) ;
) ;
}
}
if ( error is ClientException ) {
if ( error is ClientException ) {
return ExceptionDetails (
return Neon ExceptionDetails(
text: error . uri ! = null
ge tT ext: ( final context ) = > error . uri ! = null
? AppLocalizations . of ( context ) . errorUnableToReachServerAt ( error . uri ! . host )
? AppLocalizations . of ( context ) . errorUnableToReachServerAt ( error . uri ! . host )
: AppLocalizations . of ( context ) . errorUnableToReachServer ,
: AppLocalizations . of ( context ) . errorUnableToReachServer ,
) ;
) ;
}
}
if ( error is HttpException ) {
if ( error is HttpException ) {
return ExceptionDetails (
return Neon ExceptionDetails(
text: error . uri ! = null
ge tT ext: ( final context ) = > error . uri ! = null
? AppLocalizations . of ( context ) . errorUnableToReachServerAt ( error . uri ! . host )
? AppLocalizations . of ( context ) . errorUnableToReachServerAt ( error . uri ! . host )
: AppLocalizations . of ( context ) . errorUnableToReachServer ,
: AppLocalizations . of ( context ) . errorUnableToReachServer ,
) ;
) ;
}
}
if ( error is TimeoutException ) {
if ( error is TimeoutException ) {
return ExceptionDetails (
return Neon ExceptionDetails(
text: AppLocalizations . of ( context ) . errorConnectionTimedOut ,
ge tT ext: ( final context ) = > AppLocalizations . of ( context ) . errorConnectionTimedOut ,
) ;
) ;
}
}
return ExceptionDetails (
return Neon ExceptionDetails(
text: AppLocalizations . of ( context ) . errorSomethingWentWrongTryAgainLater ,
ge tT ext: ( final context ) = > AppLocalizations . of ( context ) . errorSomethingWentWrongTryAgainLater ,
) ;
) ;
}
}
@ -194,14 +180,3 @@ class NeonError extends StatelessWidget {
) ;
) ;
}
}
}
}
@ internal
class ExceptionDetails {
ExceptionDetails ( {
required this . text ,
this . isUnauthorized = false ,
} ) ;
final String text ;
final bool isUnauthorized ;
}