implemented new loadable state concept

This commit is contained in:
2024-05-05 22:58:40 +02:00
parent f58a2ec8cd
commit 6ad8203b6a
31 changed files with 1085 additions and 214 deletions

View File

@@ -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()
),
],
),
)
],
);
}
}