stack_wallet/lib/widgets/custom_loading_overlay.dart

117 lines
3.3 KiB
Dart
Raw Normal View History

2022-08-26 08:11:35 +00:00
import 'dart:async';
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/widgets/loading_indicator.dart';
class CustomLoadingOverlay extends ConsumerStatefulWidget {
const CustomLoadingOverlay({
Key? key,
required this.message,
2023-02-08 13:29:27 +00:00
this.subMessage,
2022-08-26 08:11:35 +00:00
required this.eventBus,
2023-02-08 13:29:27 +00:00
this.textColor,
2022-08-26 08:11:35 +00:00
}) : super(key: key);
final String message;
2023-02-08 13:29:27 +00:00
final String? subMessage;
2022-08-26 08:11:35 +00:00
final EventBus? eventBus;
2023-02-08 13:29:27 +00:00
final Color? textColor;
2022-08-26 08:11:35 +00:00
@override
ConsumerState<CustomLoadingOverlay> createState() =>
_CustomLoadingOverlayState();
}
class _CustomLoadingOverlayState extends ConsumerState<CustomLoadingOverlay> {
double _percent = 0;
late final StreamSubscription<double>? subscription;
@override
void initState() {
subscription = widget.eventBus?.on<double>().listen((event) {
setState(() {
_percent = event;
});
});
super.initState();
}
@override
void dispose() {
subscription?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Material(
color: Colors.transparent,
child: Center(
child: Column(
children: [
Text(
widget.message,
2023-02-08 13:29:27 +00:00
textAlign: TextAlign.center,
2022-09-22 22:17:21 +00:00
style: STextStyles.pageTitleH2(context).copyWith(
2023-02-08 13:29:27 +00:00
color: widget.textColor ??
Theme.of(context)
.extension<StackColors>()!
.loadingOverlayTextColor,
2022-08-26 08:11:35 +00:00
),
),
if (widget.eventBus != null)
const SizedBox(
height: 10,
),
if (widget.eventBus != null)
Text(
"${(_percent * 100).toStringAsFixed(2)}%",
2022-09-22 22:17:21 +00:00
style: STextStyles.pageTitleH2(context).copyWith(
2023-02-08 13:29:27 +00:00
color: widget.textColor ??
Theme.of(context)
.extension<StackColors>()!
.loadingOverlayTextColor,
2022-08-26 08:11:35 +00:00
),
),
2023-02-08 13:29:27 +00:00
if (widget.subMessage != null)
const SizedBox(
height: 10,
),
if (widget.subMessage != null)
Text(
widget.subMessage!,
textAlign: TextAlign.center,
style: STextStyles.pageTitleH2(context).copyWith(
fontSize: 14,
color: widget.textColor ??
Theme.of(context)
.extension<StackColors>()!
.loadingOverlayTextColor,
),
)
2022-08-26 08:11:35 +00:00
],
),
),
),
const SizedBox(
height: 64,
),
const Center(
child: LoadingIndicator(
width: 100,
),
),
],
);
}
}