2023-02-01 15:29:51 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:isar/isar.dart';
|
|
|
|
import 'package:stackwallet/db/main_db.dart';
|
|
|
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
2023-02-02 21:37:59 +00:00
|
|
|
import 'package:stackwallet/pages/receive_view/addresses/address_card.dart';
|
|
|
|
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
2023-03-06 21:09:32 +00:00
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
2023-02-01 15:29:51 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2023-03-06 21:09:32 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2023-02-01 15:29:51 +00:00
|
|
|
import 'package:stackwallet/widgets/background.dart';
|
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
|
|
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/loading_indicator.dart';
|
2023-03-06 21:09:32 +00:00
|
|
|
import 'package:stackwallet/widgets/toggle.dart';
|
2023-02-01 15:29:51 +00:00
|
|
|
|
2023-03-06 21:09:32 +00:00
|
|
|
class WalletAddressesView extends ConsumerStatefulWidget {
|
|
|
|
const WalletAddressesView({
|
2023-02-01 15:29:51 +00:00
|
|
|
Key? key,
|
|
|
|
required this.walletId,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2023-03-06 21:09:32 +00:00
|
|
|
static const String routeName = "/walletAddressesView";
|
2023-02-01 15:29:51 +00:00
|
|
|
|
|
|
|
final String walletId;
|
|
|
|
|
|
|
|
@override
|
2023-03-06 21:09:32 +00:00
|
|
|
ConsumerState<WalletAddressesView> createState() =>
|
|
|
|
_WalletAddressesViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _WalletAddressesViewState extends ConsumerState<WalletAddressesView> {
|
|
|
|
final bool isDesktop = Util.isDesktop;
|
|
|
|
|
|
|
|
bool _showChange = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-02-02 21:37:59 +00:00
|
|
|
final coin = ref.watch(walletsChangeNotifierProvider
|
2023-03-06 21:09:32 +00:00
|
|
|
.select((value) => value.getManager(widget.walletId).coin));
|
2023-02-01 15:29:51 +00:00
|
|
|
return ConditionalParent(
|
|
|
|
condition: !isDesktop,
|
|
|
|
builder: (child) => Background(
|
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.background,
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.backgroundAppBar,
|
|
|
|
leading: AppBarBackButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
2023-03-06 21:09:32 +00:00
|
|
|
titleSpacing: 0,
|
2023-02-01 15:29:51 +00:00
|
|
|
title: Text(
|
2023-03-06 21:09:32 +00:00
|
|
|
"Wallet addresses",
|
2023-02-01 15:29:51 +00:00
|
|
|
style: STextStyles.navBarTitle(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-03-06 21:09:32 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: isDesktop ? 56 : 48,
|
|
|
|
width: isDesktop ? 490 : null,
|
|
|
|
child: Toggle(
|
|
|
|
key: UniqueKey(),
|
|
|
|
onColor: Theme.of(context).extension<StackColors>()!.popupBG,
|
|
|
|
onText: "Receiving",
|
|
|
|
offColor: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textFieldDefaultBG,
|
|
|
|
offText: "Change",
|
|
|
|
isOn: _showChange,
|
|
|
|
onValueChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_showChange = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.transparent,
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
Constants.size.circularBorderRadius,
|
|
|
|
),
|
2023-02-01 15:29:51 +00:00
|
|
|
),
|
2023-03-06 21:09:32 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: isDesktop ? 20 : 16,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: FutureBuilder(
|
|
|
|
future: MainDB.instance
|
|
|
|
.getAddresses(widget.walletId)
|
|
|
|
.filter()
|
|
|
|
.group(
|
|
|
|
(q) => _showChange
|
|
|
|
? q.subTypeEqualTo(AddressSubType.change)
|
|
|
|
: q
|
|
|
|
.subTypeEqualTo(AddressSubType.receiving)
|
|
|
|
.or()
|
|
|
|
.subTypeEqualTo(AddressSubType.paynymReceive),
|
|
|
|
)
|
|
|
|
.and()
|
|
|
|
.not()
|
|
|
|
.typeEqualTo(AddressType.nonWallet)
|
|
|
|
.sortByDerivationIndex()
|
|
|
|
.findAll(),
|
|
|
|
builder: (context, AsyncSnapshot<List<Address>> snapshot) {
|
|
|
|
if (snapshot.connectionState == ConnectionState.done &&
|
|
|
|
snapshot.data != null) {
|
|
|
|
// listview
|
|
|
|
return ListView.separated(
|
|
|
|
itemCount: snapshot.data!.length,
|
|
|
|
separatorBuilder: (_, __) => Container(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
itemBuilder: (_, index) => AddressCard(
|
|
|
|
walletId: widget.walletId,
|
|
|
|
address: snapshot.data![index],
|
|
|
|
coin: coin,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Center(
|
|
|
|
child: LoadingIndicator(
|
|
|
|
height: 200,
|
|
|
|
width: 200,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2023-02-01 15:29:51 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|