40 lines
1.4 KiB
Dart
40 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../infrastructure/controller.dart';
|
|
import '../infrastructure/loadable_state.dart';
|
|
import '../infrastructure/state_extensions.dart';
|
|
|
|
class LoadableControllerConsumer<TController extends Controller<TState>, TState extends LoadableState> extends StatelessWidget {
|
|
final Widget Function(BuildContext context, TState state) child;
|
|
const LoadableControllerConsumer({required this.child, super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var state = context.readController<TController>().state;
|
|
return Stack(
|
|
children: [
|
|
if(!state.hasStateData()) const Center(child: CircularProgressIndicator()),
|
|
|
|
AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 100),
|
|
transitionBuilder: (Widget child, Animation<double> animation) => SlideTransition(
|
|
position: Tween<Offset>(
|
|
begin: const Offset(0.0, -1.0),
|
|
end: Offset.zero,
|
|
).animate(animation),
|
|
child: child,
|
|
),
|
|
child: state.isBackgroundLoading() ? const LinearProgressIndicator() : const SizedBox.shrink(),
|
|
),
|
|
|
|
AnimatedOpacity(
|
|
opacity: state.hasStateData() ? 1.0 : 0.0,
|
|
duration: const Duration(milliseconds: 100),
|
|
curve: Curves.easeInOut,
|
|
child: state.hasStateData() ? child(context, state) : const SizedBox.shrink()
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|