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,7 +54,13 @@ class _BuyViewState extends ConsumerState<BuyView> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType"); debugPrint("BUILD: $runtimeType");
return Stack( return TorSubscription(
onTorStatusChanged: (status) {
setState(() {
torEnabled = status != TorConnectionStatus.disconnected;
});
},
child: Stack(
children: [ children: [
SafeArea( SafeArea(
child: Padding( child: Padding(
@ -85,6 +89,7 @@ class _BuyViewState extends ConsumerState<BuyView> {
), ),
), ),
], ],
),
); );
} }
} }

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,17 +35,19 @@ 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(
onTorStatusChanged: (status) {
setState(() {
torEnabled = status != TorConnectionStatus.disconnected;
});
},
child: Stack(
children: [ children: [
DesktopScaffold( DesktopScaffold(
appBar: DesktopAppBar( appBar: DesktopAppBar(
@ -140,6 +144,7 @@ class _DesktopBuyViewState extends ConsumerState<DesktopBuyView> {
), ),
), ),
], ],
),
); );
} }
} }