TakeLogic<S, V, F> class
1. DEFINE LOGIC
TakeLogic _takeLogic;
2. INITIALIZE LOGIC
_takeLogic = TakeLogic {List{String>, void, String>(
usecase: TakeUseCase(repository: TakeRepository()));
3. DISPOSE
_takeLogic.dispose();
4. USE CASE
class TakeUseCase implements IFutureUseCase{List{String>, void, String> {
final ITakeRepository repository;
TakeUseCase({required this.repository});
@override
Future{Result{List{String>, String>> execute([void value]) async {
try {
List{String> result = await repository.getList();
return Result(success: result);
} catch (e) {
return Result(failure: e.toString());
}
}
}
5. REPOSITORY
class TakeRepository implements ITakeRepository {
@override
Future{List{String>> getList() async {
await Future.delayed(Duration(milliseconds: 1000));
return ['Onion', 'Potato', 'Carrot'];
}
}
abstract class ITakeRepository {
Future{List{String>> getList();
}
6. LISTENER
Available states:
- InitialTakeState
- WaitingTakeState
- (S) SuccessTakeState
- (F) FailureTakeState
Example:
_takeLogic.listener(
(context, state) {
if (state is InitialTakeState)
print('initial');
if (state is WaitingTakeState)
print('waiting');
if (state is SuccessTakeState)
print(state.success.toString());
if (state is FailureTakeState)
print(state.failure.toString());
},
child: Container(),
)
7. BUILDER
Available states:
- InitialTakeState
- WaitingTakeState
- (S) SuccessTakeState
- (F) FailureTakeState
Example:
_takeLogic.builder((context, state) {
if (state is InitialTakeState)
return MessageContainer(message: 'Empty');
if (state is WaitingTakeState)
return WaitingContainer();
if (state is SuccessTakeState)
return MessageContainer(message: state.success.toString());
if (state is FailureTakeState)
return MessageContainer(message: state.failure.toString());
return MessageContainer(message: 'Oops');
})
8. EVENTS
- request(value)
- init()
Example:
_takeLogic.request([V]);
_takeLogic.init();
Constructors
-
TakeLogic({required IFutureUseCase<
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
Methods
-
builder(
Widget builder(BuildContext, TakeState), {bool buildWhen(TakeState, TakeState)?}) → BlocBuilder< BlocBase, dynamic> -
dispose(
) → void -
init(
) → void -
listener(
void listener(BuildContext, TakeState), {bool listenWhen(TakeState, TakeState)?, Widget? child}) → BlocListener< BlocBase, dynamic> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
request(
[V? value]) → void -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited