AnimatedStateButton class
Botón animado con estados personalizables y widgets customizables.
Este botón transiciona suavemente entre un botón de ancho completo y estados compactos circulares, perfecto para indicar progreso de operaciones asíncronas.
Ejemplo básico:
class MyWidget extends StatefulWidget {
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
late AnimatedStateButtonController _controller;
@override
void initState() {
super.initState();
_controller = AnimatedStateButtonController(
states: {
'success': ButtonState.success(),
'error': ButtonState.error(),
},
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedStateButton(
controller: _controller,
initChild: Text('Enviar'),
onPressed: () async {
await _controller.run(() async {
await Future.delayed(Duration(seconds: 2));
return 'success';
});
},
);
}
}
Ejemplo avanzado con personalización completa:
AnimatedStateButton(
controller: controller,
initChild: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.send),
SizedBox(width: 8),
Text('Enviar formulario'),
],
),
initColor: Colors.deepPurple,
borderRadius: 12,
height: 56,
elevation: 4,
shadowColor: Colors.deepPurple.withOpacity(0.4),
onPressed: () async {
await controller.run(() async {
// Lógica de envío
final success = await sendForm();
return success ? 'success' : 'error';
});
},
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- AnimatedStateButton
Constructors
-
AnimatedStateButton({Key? key, double? width, required AnimatedStateButtonController controller, Future<
void> onPressed()?, Widget? initChild, Color initColor = Colors.black, double borderRadius = 8, EdgeInsetsGeometry padding = const EdgeInsets.symmetric(horizontal: 24.0, vertical: 16), double height = 48, double compactSize = 48, Duration animationDuration = const Duration(milliseconds: 400), Curve animationCurve = Curves.easeInOut, Duration switchDuration = const Duration(milliseconds: 300), Curve switchInCurve = Curves.easeOut, Curve switchOutCurve = Curves.easeIn, ButtonStyle? buttonStyle, bool enabled = true, double? elevation, Color? shadowColor}) -
Crea un AnimatedStateButton.
const
Properties
- animationCurve → Curve
-
Curva de animación del cambio de tamaño.
final
- animationDuration → Duration
-
Duración de la animación de cambio de tamaño del contenedor.
final
- borderRadius → double
-
Radio de las esquinas del botón en estado inicial.
final
-
Estilo personalizado del botón en estado inicial.
Si es null, usa un estilo predeterminado basado en initColor y borderRadius.
final
- compactSize → double
-
Tamaño del botón cuando está en estado compacto (circular).
final
- controller → AnimatedStateButtonController
-
Controlador de estado del botón.
final
- elevation → double?
-
Elevación del botón en estado inicial.
final
- enabled → bool
-
Si es false, el botón estará deshabilitado y no se podrá presionar.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double
-
Altura del botón (constante en todos los estados).
final
- initChild → Widget?
-
Widget mostrado en estado inicial.
Por defecto muestra el texto 'Enviar'.
final
- initColor → Color
-
Color de fondo en estado inicial.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onPressed
→ Future<
void> Function()? -
Acción asíncrona al presionar el botón.
Si es null, ejecuta una animación de demostración.
final
- padding → EdgeInsetsGeometry
-
Padding exterior del botón.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shadowColor → Color?
-
Color de sombra del botón.
final
- switchDuration → Duration
-
Duración de la transición entre widgets (AnimatedSwitcher).
final
- switchInCurve → Curve
-
Curva para la entrada de widgets.
final
- switchOutCurve → Curve
-
Curva para la salida de widgets.
final
- width → double?
-
Ancho del botón en estado inicial.
Si es null, usa el ancho disponible menos el padding horizontal.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< AnimatedStateButton> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited