remove uninstantiated and unused variables and clean up a bit

This commit is contained in:
julian 2024-05-31 11:36:37 -06:00
parent 1f0798619a
commit 16acbc366b
2 changed files with 22 additions and 59 deletions

View file

@ -8,18 +8,14 @@
* *
*/ */
import 'dart:convert';
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 '../../../../providers/db/main_db_provider.dart'; import '../../../../providers/db/main_db_provider.dart';
import '../../../../providers/global/wallets_provider.dart';
import '../../../../themes/stack_colors.dart'; import '../../../../themes/stack_colors.dart';
import '../../../../utilities/text_styles.dart'; import '../../../../utilities/text_styles.dart';
import '../../../../wallets/crypto_currency/crypto_currency.dart';
import '../../../../wallets/isar/models/wallet_info.dart'; import '../../../../wallets/isar/models/wallet_info.dart';
import '../../../../wallets/wallet/wallet.dart'; import '../../../../wallets/isar/providers/wallet_info_provider.dart';
import '../../../../widgets/background.dart'; import '../../../../widgets/background.dart';
import '../../../../widgets/custom_buttons/app_bar_icon_button.dart'; import '../../../../widgets/custom_buttons/app_bar_icon_button.dart';
import '../../../../widgets/custom_buttons/draggable_switch_button.dart'; import '../../../../widgets/custom_buttons/draggable_switch_button.dart';
@ -40,46 +36,26 @@ class LelantusSettingsView extends ConsumerStatefulWidget {
} }
class _LelantusSettingsViewState extends ConsumerState<LelantusSettingsView> { class _LelantusSettingsViewState extends ConsumerState<LelantusSettingsView> {
late final TextEditingController _controller;
late final String walletId;
final _focusNode = FocusNode();
bool _isInitialized = false;
Wallet<CryptoCurrency>? wallet;
bool _enableLelantusScanning = false;
bool _isUpdatingLelantusScanning = false; bool _isUpdatingLelantusScanning = false;
@override Future<void> _switchToggled(bool newValue) async {
void didChangeDependencies() { if (_isUpdatingLelantusScanning) return;
super.didChangeDependencies(); _isUpdatingLelantusScanning = true; // Lock mutex.
if (!_isInitialized) {
// Get the wallet. try {
wallet = ref.watch( // Toggle enableLelantusScanning in wallet info.
pWallets.select( await ref.read(pWalletInfo(widget.walletId)).updateOtherData(
(value) => value.getWallet(widget.walletId), newEntries: {
), WalletInfoKeys.enableLelantusScanning: newValue,
},
isar: ref.read(mainDBProvider).isar,
); );
} finally {
// Parse otherDataJsonString to get the enableLelantusScanning value. // ensure _isUpdatingLelantusScanning is set to false no matter what
if (wallet?.info.otherDataJsonString != null) { _isUpdatingLelantusScanning = false;
final otherDataJson = json.decode(wallet!.info.otherDataJsonString!);
_enableLelantusScanning =
otherDataJson[WalletInfoKeys.enableLelantusScanning] as bool? ??
false;
}
_isInitialized = true; // Ensure this logic runs only once
} }
} }
@override
void dispose() {
_controller.dispose();
_focusNode.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Background( return Background(
@ -107,25 +83,12 @@ class _LelantusSettingsViewState extends ConsumerState<LelantusSettingsView> {
height: 20, height: 20,
width: 40, width: 40,
child: DraggableSwitchButton( child: DraggableSwitchButton(
isOn: _enableLelantusScanning, isOn: ref.watch(
onValueChanged: (newValue) async { pWalletInfo(widget.walletId)
if (_isUpdatingLelantusScanning) return; .select((value) => value.otherData),
_isUpdatingLelantusScanning = true; // Lock mutex. )[WalletInfoKeys.enableLelantusScanning] as bool? ??
false,
// Toggle enableLelantusScanning in wallet info. onValueChanged: _switchToggled,
await wallet?.info.updateOtherData(
newEntries: {
WalletInfoKeys.enableLelantusScanning:
!_enableLelantusScanning,
},
isar: ref.read(mainDBProvider).isar,
);
setState(() {
_enableLelantusScanning = !_enableLelantusScanning;
_isUpdatingLelantusScanning = false; // Free mutex.
});
},
), ),
), ),
const SizedBox( const SizedBox(

View file

@ -1194,7 +1194,7 @@ packages:
source: hosted source: hosted
version: "0.2.0" version: "0.2.0"
monero: monero:
dependency: transitive dependency: "direct main"
description: description:
path: "." path: "."
ref: "6a17a405a1a260fa228b2f4fc94044088a4335ac" ref: "6a17a405a1a260fa228b2f4fc94044088a4335ac"