ValidLogic<S, V, F> class

1. DEFINE LOGIC

ValidLogic _validLogic;

2. INITIALIZE LOGIC

_validLogic = ValidLogic(usecase: ValidUseCase());

3. DISPOSE

_validLogic.dispose();

4. USE CASE

class ValidUseCase implements IUseCase<<String, String, String>> {
  @override
  Result<String, String> execute([String value]) {
    try {
      if (value == null) return Result(success: '');
      if (value.isEmpty) return Result(failure: 'The value must not be empty.');
      if (value.length > 3)
        return Result(failure: 'The value must be less then 4.');
      return Result(success: value);
    } catch (e, stacktrace) {
      print('BLOC_LOGIC: ${e.toString()} STACKTRACE: ${stacktrace.toString()}');
      return Result(failure: e.toString());
    }
  }
}

5. LISTENER

Available states:

  • ValidatedValidState

Example:

_validLogic.listener(
  (context, state) {
    if (state is ValidatedValidState)
      print('valided');
   },
   child: Container(),
)

6. BUILDER

Available states:

  • ValidatedValidState

Example:

_validLogic.builder(
      (context, state) {
    Result _result = (state as ValidatedValidState).result;
    return TextField(
      controller: _validController,
      decoration: InputDecoration(
        errorText: _result.hasFailure() ? _result.failure : null,
      ),
      onChanged: (value) {
        _validLogic.validate(value);
      },
    );
  },
),

7. EVENTS

  • initiate()
  • validate()

Example:

_validLogic.initiate();
_validLogic.validate();

Constructors

ValidLogic({required IUseCase<S, V, F> usecase})

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
validated bool
no setter
validBloc ValidBloc
no setter

Methods

builder(Widget builder(BuildContext, ValidState), {bool buildWhen(ValidState, ValidState)?}) BlocBuilder<BlocBase, dynamic>
dispose() → void
initiate() → void
listener(void listener(BuildContext, ValidState), {bool listenWhen(ValidState, ValidState)?, required Widget child}) BlocListener<BlocBase, dynamic>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validate([V? value]) → void

Operators

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