stack_wallet/lib/widgets/custom_loading_overlay.dart

161 lines
4.4 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
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 '../themes/stack_colors.dart';
import '../utilities/text_styles.dart';
import '../utilities/util.dart';
import 'conditional_parent.dart';
import 'loading_indicator.dart';
2022-08-26 08:11:35 +00:00
class CustomLoadingOverlay extends ConsumerStatefulWidget {
const CustomLoadingOverlay({
2024-05-27 23:56:22 +00:00
super.key,
2022-08-26 08:11:35 +00:00
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,
this.actionButton,
2024-05-27 23:56:22 +00:00
});
2022-08-26 08:11:35 +00:00
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;
final Widget? actionButton;
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;
final bool isDesktop = Util.isDesktop;
2022-08-26 08:11:35 +00:00
@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 Material(
color: Colors.transparent,
child: ConditionalParent(
condition: widget.actionButton != null,
builder: (child) => Stack(
children: [
child,
if (isDesktop)
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.all(16),
child: SizedBox(
width: 100,
child: widget.actionButton!,
2022-08-26 08:11:35 +00:00
),
),
],
),
if (!isDesktop)
Positioned(
bottom: 1,
left: 0,
right: 1,
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Expanded(child: widget.actionButton!),
],
2023-02-08 13:29:27 +00:00
),
),
),
],
2022-08-26 08:11:35 +00:00
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
widget.message,
textAlign: TextAlign.center,
style: STextStyles.pageTitleH2(context).copyWith(
color: widget.textColor ??
Theme.of(context)
.extension<StackColors>()!
.loadingOverlayTextColor,
),
),
if (widget.eventBus != null)
const SizedBox(
height: 10,
),
if (widget.eventBus != null)
Text(
"${(_percent * 100).toStringAsFixed(2)}%",
style: STextStyles.pageTitleH2(context).copyWith(
color: widget.textColor ??
Theme.of(context)
.extension<StackColors>()!
.loadingOverlayTextColor,
),
),
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,
),
),
const SizedBox(
height: 64,
),
const Center(
child: LoadingIndicator(
width: 100,
),
),
],
2022-08-26 08:11:35 +00:00
),
),
2022-08-26 08:11:35 +00:00
);
}
}