2024-02-23 00:18:02 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2024-05-06 23:04:21 -05:00
|
|
|
import 'package:immich_mobile/widgets/common/immich_loading_indicator.dart';
|
2024-02-23 00:18:02 -05:00
|
|
|
|
|
|
|
|
class DelayedLoadingIndicator extends StatelessWidget {
|
|
|
|
|
/// The delay to avoid showing the loading indicator
|
|
|
|
|
final Duration delay;
|
|
|
|
|
|
|
|
|
|
/// Defaults to using the [ImmichLoadingIndicator]
|
|
|
|
|
final Widget? child;
|
|
|
|
|
|
|
|
|
|
/// An optional fade in duration to animate the loading
|
|
|
|
|
final Duration? fadeInDuration;
|
|
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
const DelayedLoadingIndicator({super.key, this.delay = const Duration(seconds: 3), this.child, this.fadeInDuration});
|
2024-02-23 00:18:02 -05:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-02-28 16:48:59 -05:00
|
|
|
return FutureBuilder(
|
|
|
|
|
future: Future.delayed(delay),
|
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
|
late Widget c;
|
|
|
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
2025-07-29 00:34:03 +05:30
|
|
|
c = child ?? const ImmichLoadingIndicator(key: ValueKey('loading'));
|
2024-02-28 16:48:59 -05:00
|
|
|
} else {
|
|
|
|
|
c = Container(key: const ValueKey('hiding'));
|
|
|
|
|
}
|
2024-02-23 00:18:02 -05:00
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
return AnimatedSwitcher(duration: fadeInDuration ?? Duration.zero, child: c);
|
2024-02-28 16:48:59 -05:00
|
|
|
},
|
2024-02-23 00:18:02 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|