flutter-freaccess-hub/lib/components/molecular_components/throw_exception/throw_exception_widget.dart

182 lines
6.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hub/flutter_flow/nav/nav.dart';
import 'package:hub/shared/enums/enum_throw_exception.dart';
import 'package:hub/shared/utils/limited_text_size.dart';
import '/flutter_flow/flutter_flow_animations.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import 'throw_exception_model.dart';
export 'throw_exception_model.dart';
// ignore: must_be_immutable
class ThrowExceptionWidget extends StatefulWidget {
ThrowExceptionWidget(
{super.key, required this.msg, this.type = EnumThrowException.error});
final String? msg;
EnumThrowException type;
@override
State<ThrowExceptionWidget> createState() => _ThrowExceptionWidgetState();
}
class _ThrowExceptionWidgetState extends State<ThrowExceptionWidget>
with TickerProviderStateMixin {
late ThrowExceptionModel _model;
final animationsMap = <String, AnimationInfo>{};
Color _getColorByType(BuildContext context) {
switch (widget.type) {
case EnumThrowException.error:
return FlutterFlowTheme.of(context).error;
case EnumThrowException.warning:
return FlutterFlowTheme.of(context).warning;
case EnumThrowException.success:
return FlutterFlowTheme.of(context).success;
}
}
IconData _getIconByType(BuildContext context) {
switch (widget.type) {
case EnumThrowException.error:
return Icons.cancel_outlined;
case EnumThrowException.warning:
return Icons.warning_amber_outlined;
case EnumThrowException.success:
return Icons.check_circle_outline;
}
}
String _getTitleByType(BuildContext context) {
switch (widget.type) {
case EnumThrowException.error:
return FFLocalizations.of(context)
.getVariableText(ptText: "Falha :(", enText: "Fail :(");
case EnumThrowException.warning:
return FFLocalizations.of(context)
.getVariableText(ptText: "Aviso :O", enText: "Warning :O");
case EnumThrowException.success:
return FFLocalizations.of(context)
.getVariableText(ptText: "Sucesso ;)", enText: "Success ;)");
}
}
@override
void setState(VoidCallback callback) {
super.setState(callback);
_model.onUpdate();
}
@override
void initState() {
super.initState();
_model = createModel(context, () => ThrowExceptionModel());
animationsMap.addAll({
'stackOnPageLoadAnimation': AnimationInfo(
trigger: AnimationTrigger.onPageLoad,
effectsBuilder: () => [
FadeEffect(
curve: Curves.easeInOut,
delay: 0.0.ms,
duration: 600.0.ms,
begin: 0.0,
end: 1.0,
),
],
),
});
}
@override
void dispose() {
_model.maybeDispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
double limitedBodyFontSize = LimitedFontSizeUtil.getBodyFontSize(context);
double limitedHeaderFontSize =
LimitedFontSizeUtil.getHeaderFontSize(context);
return InkWell(
key: const ValueKey('ThrowExceptionWidget'),
splashColor: Colors.transparent,
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () async {
context.pop();
},
child: DecoratedBox(
decoration: BoxDecoration(
color: FlutterFlowTheme.of(context).primaryBackground,
borderRadius:
BorderRadius.circular(20.0), // Ajuste o valor conforme necessário
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 20.0),
Stack(
children: <Widget>[
Align(
alignment: const AlignmentDirectional(0.0, 0.0),
child: Icon(
_getIconByType(context),
color: _getColorByType(context),
size: 150.0,
),
),
],
).animateOnPageLoad(animationsMap['stackOnPageLoadAnimation']!),
const SizedBox(height: 20.0),
Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
_getTitleByType(context),
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily:
FlutterFlowTheme.of(context).bodyMediumFamily,
fontSize: limitedHeaderFontSize,
letterSpacing: 0.0,
fontWeight: FontWeight.bold,
useGoogleFonts: GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context).bodyMediumFamily),
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
15.0, 10.0, 15.0, 0.0),
child: Text(
valueOrDefault<String>(widget.msg, 'Message Not Found'),
overflow: TextOverflow.clip,
textAlign: TextAlign.center,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily:
FlutterFlowTheme.of(context).bodyMediumFamily,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context).bodyMediumFamily),
fontSize: limitedBodyFontSize,
),
),
),
],
),
],
),
),
),
);
}
}