wrapped stack in TorSubscription for tor dialog

This commit is contained in:
ryleedavis 2023-09-15 09:25:18 -06:00
parent 5ac7ae95cb
commit c810f9dc15
2 changed files with 131 additions and 121 deletions

View file

@ -12,10 +12,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart'; import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
import 'package:stackwallet/pages/buy_view/buy_form.dart'; import 'package:stackwallet/pages/buy_view/buy_form.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart'; import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart';
import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/widgets/stack_dialog.dart'; import 'package:stackwallet/widgets/stack_dialog.dart';
import 'package:stackwallet/widgets/tor_subscription.dart';
class BuyView extends ConsumerStatefulWidget { class BuyView extends ConsumerStatefulWidget {
const BuyView({ const BuyView({
@ -43,11 +45,7 @@ class _BuyViewState extends ConsumerState<BuyView> {
coin = widget.coin; coin = widget.coin;
tokenContract = widget.tokenContract; tokenContract = widget.tokenContract;
WidgetsBinding.instance.addPostFrameCallback((_) async { torEnabled = ref.read(pTorService).enabled;
setState(() {
torEnabled = ref.read(prefsChangeNotifierProvider).useTor;
});
});
super.initState(); super.initState();
} }
@ -56,35 +54,42 @@ class _BuyViewState extends ConsumerState<BuyView> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType"); debugPrint("BUILD: $runtimeType");
return Stack( return TorSubscription(
children: [ onTorStatusChanged: (status) {
SafeArea( setState(() {
child: Padding( torEnabled = status != TorConnectionStatus.disconnected;
padding: const EdgeInsets.only( });
left: 16, },
right: 16, child: Stack(
top: 16, children: [
), SafeArea(
child: BuyForm( child: Padding(
coin: coin, padding: const EdgeInsets.only(
tokenContract: tokenContract, left: 16,
right: 16,
top: 16,
),
child: BuyForm(
coin: coin,
tokenContract: tokenContract,
),
), ),
), ),
), if (torEnabled)
if (torEnabled) Container(
Container( color: Theme.of(context)
color: Theme.of(context) .extension<StackColors>()!
.extension<StackColors>()! .overlay
.overlay .withOpacity(0.7),
.withOpacity(0.7), height: MediaQuery.of(context).size.height,
height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width,
width: MediaQuery.of(context).size.width, child: const StackDialog(
child: const StackDialog( title: "Tor is enabled",
title: "Tor is enabled", message: "Purchasing not available while Tor is enabled",
message: "Purchasing not available while Tor is enabled", ),
), ),
), ],
], ),
); );
} }
} }

View file

@ -11,13 +11,15 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/pages/buy_view/buy_form.dart'; import 'package:stackwallet/pages/buy_view/buy_form.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart'; import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart';
import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart'; import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart'; import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:stackwallet/widgets/tor_subscription.dart';
class DesktopBuyView extends ConsumerStatefulWidget { class DesktopBuyView extends ConsumerStatefulWidget {
const DesktopBuyView({Key? key}) : super(key: key); const DesktopBuyView({Key? key}) : super(key: key);
@ -33,113 +35,116 @@ class _DesktopBuyViewState extends ConsumerState<DesktopBuyView> {
@override @override
void initState() { void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) async { torEnabled = ref.read(pTorService).enabled;
setState(() {
torEnabled = ref.read(prefsChangeNotifierProvider).useTor;
});
});
super.initState(); super.initState();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Stack( return TorSubscription(
children: [ onTorStatusChanged: (status) {
DesktopScaffold( setState(() {
appBar: DesktopAppBar( torEnabled = status != TorConnectionStatus.disconnected;
isCompactHeight: true, });
leading: Padding( },
child: Stack(
children: [
DesktopScaffold(
appBar: DesktopAppBar(
isCompactHeight: true,
leading: Padding(
padding: const EdgeInsets.only(
left: 24,
),
child: Text(
"Buy crypto",
style: STextStyles.desktopH3(context),
),
),
),
body: Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
left: 24, left: 24,
right: 24,
bottom: 24,
), ),
child: Text( child: Row(
"Buy crypto", crossAxisAlignment: CrossAxisAlignment.start,
style: STextStyles.desktopH3(context), children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
SizedBox(
height: 16,
),
RoundedWhiteContainer(
padding: EdgeInsets.all(24),
child: BuyForm(),
),
],
),
),
const SizedBox(
width: 16,
),
// Expanded(
// child: Row(
// children: const [
// Expanded(
// child: DesktopTradeHistory(),
// ),
// ],
// ),
// ),
],
), ),
), ),
), ),
body: Padding( if (torEnabled)
padding: const EdgeInsets.only( Container(
left: 24, color: Theme.of(context)
right: 24, .extension<StackColors>()!
bottom: 24, .overlay
), .withOpacity(0.7),
child: Row( height: MediaQuery.of(context).size.height,
crossAxisAlignment: CrossAxisAlignment.start, width: MediaQuery.of(context).size.width,
children: [ child: DesktopDialog(
Expanded( maxHeight: 200,
maxWidth: 350,
child: Padding(
padding: const EdgeInsets.all(
15.0,
),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, // crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start, // mainAxisAlignment: MainAxisAlignment.center,
children: const [ children: [
SizedBox( Text(
height: 16, "Tor is enabled",
textAlign: TextAlign.center,
style: STextStyles.pageTitleH1(context),
), ),
RoundedWhiteContainer( const SizedBox(
padding: EdgeInsets.all(24), height: 30,
child: BuyForm(), ),
Text(
"Purchasing not available while Tor is enabled",
textAlign: TextAlign.center,
style: STextStyles.desktopTextMedium(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.infoItemLabel,
),
), ),
], ],
), ),
), ),
const SizedBox(
width: 16,
),
// Expanded(
// child: Row(
// children: const [
// Expanded(
// child: DesktopTradeHistory(),
// ),
// ],
// ),
// ),
],
),
),
),
if (torEnabled)
Container(
color: Theme.of(context)
.extension<StackColors>()!
.overlay
.withOpacity(0.7),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: DesktopDialog(
maxHeight: 200,
maxWidth: 350,
child: Padding(
padding: const EdgeInsets.all(
15.0,
),
child: Column(
// crossAxisAlignment: CrossAxisAlignment.center,
// mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Tor is enabled",
textAlign: TextAlign.center,
style: STextStyles.pageTitleH1(context),
),
const SizedBox(
height: 30,
),
Text(
"Purchasing not available while Tor is enabled",
textAlign: TextAlign.center,
style: STextStyles.desktopTextMedium(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.infoItemLabel,
),
),
],
),
), ),
), ),
), ],
], ),
); );
} }
} }