41 lines
1.4 KiB
Dart
41 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../infrastructure/controller.dart';
|
|
import '../infrastructure/loadable_state.dart';
|
|
import '../infrastructure/state_extensions.dart';
|
|
import 'components/background_loading_indicator.dart';
|
|
import 'components/error_bar.dart';
|
|
import 'components/primary_loading_indicator.dart';
|
|
|
|
class LoadableControllerConsumer<TController extends Controller<TState>, TState extends LoadableState> extends StatelessWidget {
|
|
final Widget child;
|
|
const LoadableControllerConsumer({required this.child, super.key});
|
|
|
|
final Duration animationDuration = const Duration(milliseconds: 200);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var state = context.readController<TController>().state;
|
|
return Column(
|
|
children: [
|
|
ErrorBar(visible: state.errorBarVisible()),
|
|
Expanded(
|
|
child: Stack(
|
|
children: [
|
|
PrimaryLoadingIndicator(visible: !state.hasStateData()),
|
|
BackgroundLoadingIndicator(visible: state.isBackgroundLoading() && !state.errorBarVisible()),
|
|
|
|
AnimatedOpacity(
|
|
opacity: state.hasStateData() ? 1.0 : 0.0,
|
|
duration: animationDuration,
|
|
curve: Curves.easeInOut,
|
|
child: state.hasStateData() ? child : const SizedBox.shrink()
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
}
|