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-02-28 17:02:38 +00:00
|
|
|
import 'package:stackwallet/pages/add_wallet_views/add_token_view/add_token_view.dart';
|
2023-01-20 17:24:19 +00:00
|
|
|
import 'package:stackwallet/pages/token_view/sub_widgets/my_tokens_list.dart';
|
2023-03-01 00:36:54 +00:00
|
|
|
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
2023-03-23 16:22:05 +00:00
|
|
|
import 'package:stackwallet/services/coins/ethereum/ethereum_wallet.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/theme/stack_colors.dart';
|
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
|
|
|
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/desktop/desktop_app_bar.dart';
|
2023-02-23 22:59:58 +00:00
|
|
|
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
|
2023-01-16 13:19:32 +00:00
|
|
|
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-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-01-16 13:19:32 +00:00
|
|
|
final isDesktop = Util.isDesktop;
|
|
|
|
|
|
|
|
return MasterScaffold(
|
|
|
|
background: Theme.of(context).extension<StackColors>()!.background,
|
|
|
|
isDesktop: isDesktop,
|
|
|
|
appBar: isDesktop
|
|
|
|
? DesktopAppBar(
|
|
|
|
isCompactHeight: true,
|
|
|
|
background: Theme.of(context).extension<StackColors>()!.popupBG,
|
|
|
|
leading: Row(
|
|
|
|
children: [
|
|
|
|
const SizedBox(
|
|
|
|
width: 32,
|
|
|
|
),
|
|
|
|
AppBarIconButton(
|
|
|
|
size: 32,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textFieldDefaultBG,
|
|
|
|
shadows: const [],
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.arrowLeft,
|
|
|
|
width: 18,
|
|
|
|
height: 18,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.topNavIconPrimary,
|
|
|
|
),
|
|
|
|
onPressed: Navigator.of(context).pop,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
|
|
|
),
|
|
|
|
Text(
|
2023-03-01 00:36:54 +00:00
|
|
|
"${ref.watch(
|
|
|
|
walletsChangeNotifierProvider.select((value) =>
|
|
|
|
value.getManager(widget.walletId).walletName),
|
|
|
|
)} Tokens",
|
2023-01-16 13:19:32 +00:00
|
|
|
style: STextStyles.desktopH3(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: 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(
|
2023-03-01 00:36:54 +00:00
|
|
|
"${ref.watch(
|
|
|
|
walletsChangeNotifierProvider.select(
|
|
|
|
(value) => value.getManager(widget.walletId).walletName),
|
|
|
|
)} Tokens",
|
2023-01-16 13:19:32 +00:00
|
|
|
style: STextStyles.navBarTitle(context),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 10,
|
|
|
|
bottom: 10,
|
|
|
|
right: 20,
|
|
|
|
),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 1,
|
|
|
|
child: AppBarIconButton(
|
2023-02-28 17:02:38 +00:00
|
|
|
key: const Key("addTokenAppBarIconButtonKey"),
|
2023-01-16 13:19:32 +00:00
|
|
|
size: 36,
|
|
|
|
shadows: const [],
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.background,
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.circlePlusDark,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorDark,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
),
|
2023-03-03 00:40:12 +00:00
|
|
|
onPressed: () async {
|
|
|
|
final result = await Navigator.of(context).pushNamed(
|
2023-02-28 17:02:38 +00:00
|
|
|
AddTokenView.routeName,
|
2023-02-28 19:26:17 +00:00
|
|
|
arguments: widget.walletId,
|
2023-01-16 13:19:32 +00:00
|
|
|
);
|
2023-03-03 00:40:12 +00:00
|
|
|
|
|
|
|
if (mounted && result == 42) {
|
|
|
|
setState(() {});
|
|
|
|
}
|
2023-01-16 13:19:32 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: isDesktop ? 20 : 12,
|
|
|
|
top: isDesktop ? 20 : 12,
|
|
|
|
right: isDesktop ? 20 : 12,
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(4),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
ConditionalParent(
|
|
|
|
condition: isDesktop,
|
|
|
|
builder: (child) => SizedBox(
|
|
|
|
width: 570,
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
child: ConditionalParent(
|
|
|
|
condition: !isDesktop,
|
|
|
|
builder: (child) => Expanded(
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
Constants.size.circularBorderRadius,
|
|
|
|
),
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (isDesktop)
|
|
|
|
const SizedBox(
|
|
|
|
width: 20,
|
|
|
|
),
|
|
|
|
// const NoTransActionsFound(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
2023-01-20 17:24:19 +00:00
|
|
|
Expanded(
|
|
|
|
child: MyTokensList(
|
2023-02-28 17:02:38 +00:00
|
|
|
walletId: widget.walletId,
|
2023-03-23 16:22:05 +00:00
|
|
|
searchTerm: _searchString,
|
|
|
|
tokenContracts: ref
|
|
|
|
.watch(walletsChangeNotifierProvider.select((value) => value
|
|
|
|
.getManager(widget.walletId)
|
|
|
|
.wallet as EthereumWallet))
|
|
|
|
.getWalletTokenContractAddresses(),
|
2023-02-28 17:02:38 +00:00
|
|
|
),
|
2023-01-20 17:24:19 +00:00
|
|
|
),
|
2023-01-16 13:19:32 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|