2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:stackwallet/providers/exchange/changenow_initial_load_status.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/widgets/custom_loading_overlay.dart';
|
|
|
|
import 'package:stackwallet/widgets/stack_dialog.dart';
|
|
|
|
|
|
|
|
class ExchangeLoadingOverlayView extends ConsumerStatefulWidget {
|
2022-09-09 14:03:36 +00:00
|
|
|
const ExchangeLoadingOverlayView({
|
|
|
|
Key? key,
|
|
|
|
required this.unawaitedLoad,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final VoidCallback unawaitedLoad;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<ExchangeLoadingOverlayView> createState() =>
|
|
|
|
_ExchangeLoadingOverlayViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ExchangeLoadingOverlayViewState
|
|
|
|
extends ConsumerState<ExchangeLoadingOverlayView> {
|
|
|
|
late ChangeNowLoadStatus _statusEst;
|
|
|
|
late ChangeNowLoadStatus _statusFixed;
|
|
|
|
|
|
|
|
bool userReloaded = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_statusEst =
|
|
|
|
ref.read(changeNowEstimatedInitialLoadStatusStateProvider.state).state;
|
|
|
|
_statusFixed =
|
|
|
|
ref.read(changeNowFixedInitialLoadStatusStateProvider.state).state;
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
debugPrint("BUILD: $runtimeType");
|
|
|
|
|
|
|
|
ref.listen(
|
|
|
|
changeNowEstimatedInitialLoadStatusStateProvider
|
|
|
|
.select((value) => value), (previous, next) {
|
|
|
|
if (next is ChangeNowLoadStatus) {
|
|
|
|
setState(() {
|
|
|
|
_statusEst = next;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ref.listen(
|
|
|
|
changeNowFixedInitialLoadStatusStateProvider.select((value) => value),
|
|
|
|
(previous, next) {
|
|
|
|
if (next is ChangeNowLoadStatus) {
|
|
|
|
setState(() {
|
|
|
|
_statusFixed = next;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
if (_statusEst == ChangeNowLoadStatus.loading ||
|
|
|
|
(_statusFixed == ChangeNowLoadStatus.loading && userReloaded))
|
|
|
|
Container(
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.overlay
|
|
|
|
.withOpacity(0.7),
|
2022-08-26 08:11:35 +00:00
|
|
|
child: const CustomLoadingOverlay(
|
2022-10-04 22:10:50 +00:00
|
|
|
message: "Loading Exchange data", eventBus: null),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
2022-09-09 14:03:36 +00:00
|
|
|
if ((_statusEst == ChangeNowLoadStatus.failed ||
|
|
|
|
_statusFixed == ChangeNowLoadStatus.failed) &&
|
|
|
|
_statusEst != ChangeNowLoadStatus.loading &&
|
|
|
|
_statusFixed != ChangeNowLoadStatus.loading)
|
2022-08-26 08:11:35 +00:00
|
|
|
Container(
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.overlay
|
|
|
|
.withOpacity(0.7),
|
2022-08-26 08:11:35 +00:00
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
StackDialog(
|
2022-10-04 22:10:50 +00:00
|
|
|
title: "Failed to fetch Exchange data",
|
2022-08-26 08:11:35 +00:00
|
|
|
message:
|
2022-10-04 22:10:50 +00:00
|
|
|
"Exchange requires a working internet connection. Tap OK to try fetching again.",
|
2022-08-26 08:11:35 +00:00
|
|
|
rightButton: TextButton(
|
2022-09-22 23:48:50 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2023-01-24 19:29:12 +00:00
|
|
|
.getSecondaryEnabledButtonStyle(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
child: Text(
|
|
|
|
"OK",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.button(context).copyWith(
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondary,
|
2022-09-21 21:59:52 +00:00
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
onPressed: () {
|
2022-09-09 14:03:36 +00:00
|
|
|
userReloaded = true;
|
|
|
|
widget.unawaitedLoad();
|
2022-08-26 08:11:35 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|