2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-01-16 13:19:32 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter_svg/svg.dart';
|
2023-04-07 14:45:05 +00:00
|
|
|
import 'package:stackwallet/pages/add_wallet_views/add_token_view/edit_wallet_tokens_view.dart';
|
2023-01-20 17:24:19 +00:00
|
|
|
import 'package:stackwallet/pages/token_view/sub_widgets/my_tokens_list.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2023-01-16 13:19:32 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
2023-02-23 22:59:58 +00:00
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
2023-01-16 13:19:32 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2023-02-23 22:59:58 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2023-11-03 19:46:55 +00:00
|
|
|
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
|
2023-04-07 21:08:06 +00:00
|
|
|
import 'package:stackwallet/widgets/background.dart';
|
2023-02-23 22:59:58 +00:00
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
2023-01-16 13:19:32 +00:00
|
|
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/icon_widgets/x_icon.dart';
|
|
|
|
import 'package:stackwallet/widgets/stack_text_field.dart';
|
|
|
|
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
2023-01-25 09:29:20 +00:00
|
|
|
|
2023-01-16 13:19:32 +00:00
|
|
|
class MyTokensView extends ConsumerStatefulWidget {
|
|
|
|
const MyTokensView({
|
|
|
|
Key? key,
|
2023-01-25 09:29:20 +00:00
|
|
|
required this.walletId,
|
2023-01-16 13:19:32 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
static const String routeName = "/myTokens";
|
2023-01-25 09:29:20 +00:00
|
|
|
final String walletId;
|
2023-01-16 13:19:32 +00:00
|
|
|
|
|
|
|
@override
|
2023-03-23 16:22:05 +00:00
|
|
|
ConsumerState<MyTokensView> createState() => _MyTokensViewState();
|
2023-01-16 13:19:32 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 16:22:05 +00:00
|
|
|
class _MyTokensViewState extends ConsumerState<MyTokensView> {
|
2023-04-07 21:08:06 +00:00
|
|
|
final bool isDesktop = Util.isDesktop;
|
|
|
|
|
2023-01-20 17:24:19 +00:00
|
|
|
late final String walletAddress;
|
2023-01-16 13:19:32 +00:00
|
|
|
late final TextEditingController _searchController;
|
|
|
|
final searchFieldFocusNode = FocusNode();
|
2023-03-03 00:40:12 +00:00
|
|
|
String _searchString = "";
|
|
|
|
|
2023-01-16 13:19:32 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_searchController = TextEditingController();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_searchController.dispose();
|
|
|
|
searchFieldFocusNode.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-03-23 16:22:05 +00:00
|
|
|
debugPrint("BUILD: $runtimeType");
|
|
|
|
|
2023-04-07 21:08:06 +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>()!.background,
|
|
|
|
leading: AppBarBackButton(
|
|
|
|
onPressed: () async {
|
|
|
|
if (FocusScope.of(context).hasFocus) {
|
|
|
|
FocusScope.of(context).unfocus();
|
|
|
|
await Future<void>.delayed(const Duration(milliseconds: 75));
|
|
|
|
}
|
|
|
|
if (mounted) {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
"${ref.watch(
|
2023-11-03 19:46:55 +00:00
|
|
|
pWalletName(widget.walletId),
|
2023-04-07 21:08:06 +00:00
|
|
|
)} Tokens",
|
|
|
|
style: STextStyles.navBarTitle(context),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 10,
|
|
|
|
bottom: 10,
|
|
|
|
right: 20,
|
|
|
|
),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 1,
|
|
|
|
child: AppBarIconButton(
|
|
|
|
key: const Key("addTokenAppBarIconButtonKey"),
|
|
|
|
size: 36,
|
2023-01-16 13:19:32 +00:00
|
|
|
shadows: const [],
|
2023-04-07 21:08:06 +00:00
|
|
|
color:
|
|
|
|
Theme.of(context).extension<StackColors>()!.background,
|
2023-01-16 13:19:32 +00:00
|
|
|
icon: SvgPicture.asset(
|
2023-04-13 14:53:17 +00:00
|
|
|
Assets.svg.circlePlusFilled,
|
2023-01-16 13:19:32 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2023-04-13 14:53:17 +00:00
|
|
|
.topNavIconPrimary,
|
2023-04-07 21:08:06 +00:00
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2023-01-16 13:19:32 +00:00
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
onPressed: () async {
|
|
|
|
final result = await Navigator.of(context).pushNamed(
|
|
|
|
EditWalletTokensView.routeName,
|
|
|
|
arguments: widget.walletId,
|
|
|
|
);
|
2023-03-03 00:40:12 +00:00
|
|
|
|
2023-04-07 21:08:06 +00:00
|
|
|
if (mounted && result == 42) {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
},
|
2023-01-16 13:19:32 +00:00
|
|
|
),
|
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 12,
|
|
|
|
top: 12,
|
|
|
|
right: 12,
|
2023-01-16 13:19:32 +00:00
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
child: child,
|
|
|
|
),
|
2023-01-16 13:19:32 +00:00
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.all(isDesktop ? 0 : 4),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
ConditionalParent(
|
|
|
|
condition: isDesktop,
|
|
|
|
builder: (child) => Expanded(
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
child: ConditionalParent(
|
|
|
|
condition: !isDesktop,
|
|
|
|
builder: (child) => Expanded(
|
2023-01-16 13:19:32 +00:00
|
|
|
child: child,
|
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
Constants.size.circularBorderRadius,
|
2023-01-16 13:19:32 +00:00
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
child: TextField(
|
|
|
|
autocorrect: !isDesktop,
|
|
|
|
enableSuggestions: !isDesktop,
|
|
|
|
controller: _searchController,
|
|
|
|
focusNode: searchFieldFocusNode,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_searchString = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
style: isDesktop
|
|
|
|
? STextStyles.desktopTextExtraSmall(context)
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textFieldActiveText,
|
|
|
|
height: 1.8,
|
|
|
|
)
|
|
|
|
: STextStyles.field(context),
|
|
|
|
decoration: standardInputDecoration(
|
|
|
|
"Search...",
|
|
|
|
searchFieldFocusNode,
|
|
|
|
context,
|
|
|
|
desktopMed: isDesktop,
|
|
|
|
).copyWith(
|
|
|
|
prefixIcon: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: isDesktop ? 12 : 10,
|
|
|
|
vertical: isDesktop ? 18 : 16,
|
|
|
|
),
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
Assets.svg.search,
|
|
|
|
width: isDesktop ? 20 : 16,
|
|
|
|
height: isDesktop ? 20 : 16,
|
2023-01-16 13:19:32 +00:00
|
|
|
),
|
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
suffixIcon: _searchController.text.isNotEmpty
|
|
|
|
? Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 0),
|
|
|
|
child: UnconstrainedBox(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
TextFieldIconButton(
|
|
|
|
child: const XIcon(),
|
|
|
|
onTap: () async {
|
|
|
|
setState(() {
|
|
|
|
_searchController.text = "";
|
|
|
|
_searchString = "";
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
2023-01-16 13:19:32 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
),
|
|
|
|
],
|
2023-01-16 13:19:32 +00:00
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: MyTokensList(
|
|
|
|
walletId: widget.walletId,
|
|
|
|
searchTerm: _searchString,
|
2024-01-10 18:21:28 +00:00
|
|
|
tokenContracts: ref.watch(pWalletTokenAddresses(widget.walletId)),
|
2023-01-20 17:24:19 +00:00
|
|
|
),
|
2023-04-07 21:08:06 +00:00
|
|
|
),
|
|
|
|
],
|
2023-01-16 13:19:32 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|