temp firo balance dropdown

This commit is contained in:
julian 2022-11-14 07:37:24 -06:00
parent 649e7c6a0b
commit 94709623c4

View file

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -9,7 +10,6 @@ import 'package:stackwallet/models/contact_address_entry.dart';
import 'package:stackwallet/models/send_view_auto_fill_data.dart'; import 'package:stackwallet/models/send_view_auto_fill_data.dart';
import 'package:stackwallet/pages/send_view/confirm_transaction_view.dart'; import 'package:stackwallet/pages/send_view/confirm_transaction_view.dart';
import 'package:stackwallet/pages/send_view/sub_widgets/building_transaction_dialog.dart'; import 'package:stackwallet/pages/send_view/sub_widgets/building_transaction_dialog.dart';
import 'package:stackwallet/pages/send_view/sub_widgets/firo_balance_selection_sheet.dart';
import 'package:stackwallet/pages/send_view/sub_widgets/transaction_fee_selection_sheet.dart'; import 'package:stackwallet/pages/send_view/sub_widgets/transaction_fee_selection_sheet.dart';
import 'package:stackwallet/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/address_book_address_chooser.dart'; import 'package:stackwallet/pages_desktop_specific/home/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/address_book_address_chooser.dart';
import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/providers/providers.dart';
@ -550,13 +550,13 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
Future<String?> _firoBalanceFuture( Future<String?> _firoBalanceFuture(
ChangeNotifierProvider<Manager> provider, ChangeNotifierProvider<Manager> provider,
String locale, String locale,
bool private,
) async { ) async {
final wallet = ref.read(provider).wallet as FiroWallet?; final wallet = ref.read(provider).wallet as FiroWallet?;
if (wallet != null) { if (wallet != null) {
Decimal? balance; Decimal? balance;
if (ref.read(publicPrivateBalanceStateProvider.state).state == if (private) {
"Private") {
balance = await wallet.availablePrivateBalance(); balance = await wallet.availablePrivateBalance();
} else { } else {
balance = await wallet.availablePublicBalance(); balance = await wallet.availablePublicBalance();
@ -572,24 +572,21 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
Widget firoBalanceFutureBuilder( Widget firoBalanceFutureBuilder(
BuildContext context, BuildContext context,
AsyncSnapshot<String?> snapshot, AsyncSnapshot<String?> snapshot,
bool private,
) { ) {
if (snapshot.connectionState == ConnectionState.done && snapshot.hasData) { if (snapshot.connectionState == ConnectionState.done && snapshot.hasData) {
if (ref.read(publicPrivateBalanceStateProvider.state).state == if (private) {
"Private") {
_privateBalanceString = snapshot.data!; _privateBalanceString = snapshot.data!;
} else { } else {
_publicBalanceString = snapshot.data!; _publicBalanceString = snapshot.data!;
} }
} }
if (ref.read(publicPrivateBalanceStateProvider.state).state == "Private" && if (private && _privateBalanceString != null) {
_privateBalanceString != null) {
return Text( return Text(
"$_privateBalanceString ${coin.ticker}", "$_privateBalanceString ${coin.ticker}",
style: STextStyles.itemSubtitle(context), style: STextStyles.itemSubtitle(context),
); );
} else if (ref.read(publicPrivateBalanceStateProvider.state).state == } else if (!private && _publicBalanceString != null) {
"Public" &&
_publicBalanceString != null) {
return Text( return Text(
"$_publicBalanceString ${coin.ticker}", "$_publicBalanceString ${coin.ticker}",
style: STextStyles.itemSubtitle(context), style: STextStyles.itemSubtitle(context),
@ -889,71 +886,95 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
height: 10, height: 10,
), ),
if (coin == Coin.firo) if (coin == Coin.firo)
Stack( DropdownButtonHideUnderline(
children: [ child: DropdownButton2(
TextField( offset: const Offset(0, -10),
autocorrect: Util.isDesktop ? false : true, isExpanded: true,
enableSuggestions: Util.isDesktop ? false : true, dropdownElevation: 0,
readOnly: true, value: ref.watch(publicPrivateBalanceStateProvider.state).state,
textInputAction: TextInputAction.none, items: [
), DropdownMenuItem(
Padding( value: "Private",
padding: const EdgeInsets.symmetric(
horizontal: 12,
),
child: RawMaterialButton(
splashColor:
Theme.of(context).extension<StackColors>()!.highlight,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
onPressed: () {
showModalBottomSheet<dynamic>(
backgroundColor: Colors.transparent,
context: context,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
builder: (_) => FiroBalanceSelectionSheet(
walletId: walletId,
),
);
},
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Row( Text(
children: [ "Private balance",
Text( style: STextStyles.itemSubtitle12(context),
"${ref.watch(publicPrivateBalanceStateProvider.state).state} balance",
style: STextStyles.itemSubtitle12(context),
),
const SizedBox(
width: 10,
),
FutureBuilder(
future: _firoBalanceFuture(provider, locale),
builder: firoBalanceFutureBuilder,
),
],
), ),
SvgPicture.asset( const SizedBox(
Assets.svg.chevronDown, width: 10,
width: 8, ),
height: 4, FutureBuilder(
color: Theme.of(context) future: _firoBalanceFuture(provider, locale, true),
.extension<StackColors>()! builder: (context, AsyncSnapshot<String?> snapshot) =>
.textSubtitle2, firoBalanceFutureBuilder(
context,
snapshot,
true,
),
), ),
], ],
), ),
), ),
) DropdownMenuItem(
], value: "Public",
child: Row(
children: [
Text(
"Public balance",
style: STextStyles.itemSubtitle12(context),
),
const SizedBox(
width: 10,
),
FutureBuilder(
future: _firoBalanceFuture(provider, locale, false),
builder: (context, AsyncSnapshot<String?> snapshot) =>
firoBalanceFutureBuilder(
context,
snapshot,
false,
),
),
],
),
),
],
onChanged: (value) {
if (value is String) {
setState(() {
ref.watch(publicPrivateBalanceStateProvider.state).state =
value;
});
}
},
icon: SvgPicture.asset(
Assets.svg.chevronDown,
width: 12,
height: 6,
color: Theme.of(context).extension<StackColors>()!.textDark3,
),
buttonPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
buttonDecoration: BoxDecoration(
color: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
dropdownDecoration: BoxDecoration(
color: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
),
), ),
if (coin == Coin.firo) if (coin == Coin.firo)
const SizedBox( const SizedBox(