implemented new loadable state concept
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../loadable_state.dart';
|
||||
import 'loadable_state_background_loading.dart';
|
||||
import 'loadable_state_error_bar.dart';
|
||||
import 'loadable_state_primary_loading.dart';
|
||||
|
||||
// TODO might be a simpler way
|
||||
class LoadableStateConsumer<TController extends Bloc<dynamic, TWrappedState>, TWrappedState extends LoadableState<TState>, TState> extends StatelessWidget {
|
||||
final Widget Function(TState state) child;
|
||||
const LoadableStateConsumer({required this.child, super.key});
|
||||
|
||||
static Duration animationDuration = const Duration(milliseconds: 200);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var state = context.read<TController>().state as LoadableState<TState>;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
LoadableStateErrorBar(visible: state.showError()),
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: [
|
||||
LoadableStatePrimaryLoading(visible: state.showPrimaryLoading()),
|
||||
LoadableStateBackgroundLoading(visible: state.showBackgroundLoading()),
|
||||
|
||||
AnimatedOpacity(
|
||||
opacity: state.showContent() ? 1.0 : 0.0,
|
||||
duration: animationDuration,
|
||||
curve: Curves.easeInOut,
|
||||
child: state.showContent() ? child(state.data) : const SizedBox.shrink()
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user