AnimatedStateButtonController class

Controlador para manejar el estado del botón animado.

Permite controlar estados personalizados del botón y ejecutar tareas asíncronas con manejo automático de estados de carga, éxito y error.

Ejemplo básico:

final controller = AnimatedStateButtonController(
  states: {
    'success': ButtonState.success(),
    'error': ButtonState.error(),
  },
);

// Cambiar manualmente a un estado
controller.changeState('success');

Ejemplo avanzado con estados personalizados:

final controller = AnimatedStateButtonController(
  states: {
    'success': ButtonState.success(),
    'error': ButtonState.error(),
    'warning': ButtonState(
      id: 'warning',
      color: Colors.orange,
      child: Icon(Icons.warning, color: Colors.white),
    ),
  },
  stateCallbacks: {
    'success': () => print('¡Operación exitosa!'),
    'error': () => print('Hubo un error'),
  },
);

// Ejecutar una tarea asíncrona
await controller.run(() async {
  await Future.delayed(Duration(seconds: 2));
  // Simular lógica de negocio
  if (Random().nextBool()) {
    return 'success';
  } else {
    return 'error';
  }
});
Inheritance

Constructors

AnimatedStateButtonController({Map<String, ButtonState>? states, ButtonState? loadingState, Map<String, VoidCallback> stateCallbacks = const {}})
Crea un controlador de estados para AnimatedStateButton.

Properties

currentState ButtonState?
Obtiene el estado actual como objeto ButtonState. Retorna null si está en estado inicial.
no setter
currentStateId String
Estado actual del botón como String (id del estado).
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isInit bool
Verifica si el botón está en estado inicial.
no setter
isLoading bool
Verifica si el botón está cargando.
no setter
loadingState ButtonState
Estado de carga (siempre presente). Se puede personalizar pasando un loadingState en el constructor.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateCallbacks Map<String, VoidCallback>
Callbacks opcionales que se ejecutan cuando se alcanza cada estado. La clave es el id del estado y el valor es la función a ejecutar.
final
states Map<String, ButtonState>
Estados disponibles del botón. Cada clave es el id del estado y el valor es el ButtonState correspondiente.
final
value String
The current value stored in this notifier.
getter/setter pairinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
changeState(String stateId) → void
Cambia a un estado personalizado.
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
inherited
init() → void
Cambia el estado a inicial.
loading() → void
Cambia el estado a carga.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
run(Future<String> task(), {Duration stateDelay = const Duration(milliseconds: 600), bool resetToInit = true}) Future<void>
Ejecuta una tarea asíncrona y maneja los estados automáticamente.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited