stack_wallet/lib/pages/paynym/paynym_home_view.dart

306 lines
10 KiB
Dart
Raw Normal View History

2022-12-21 17:08:14 +00:00
import 'dart:async';
2022-12-20 23:00:03 +00:00
import 'package:flutter/material.dart';
2022-12-21 17:08:14 +00:00
import 'package:flutter/services.dart';
2022-12-21 23:02:14 +00:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
2022-12-21 16:17:53 +00:00
import 'package:flutter_svg/svg.dart';
2022-12-21 17:08:14 +00:00
import 'package:stackwallet/notifications/show_flush_bar.dart';
2022-12-21 19:46:50 +00:00
import 'package:stackwallet/pages/paynym/add_new_paynym_follow_view.dart';
2022-12-21 17:14:50 +00:00
import 'package:stackwallet/pages/paynym/dialogs/paynym_qr_popup.dart';
import 'package:stackwallet/pages/paynym/subwidgets/paynym_bot.dart';
import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart';
2022-12-21 16:17:53 +00:00
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/format.dart';
2022-12-20 23:00:03 +00:00
import 'package:stackwallet/utilities/text_styles.dart';
2022-12-21 16:17:53 +00:00
import 'package:stackwallet/utilities/theme/stack_colors.dart';
2022-12-20 23:00:03 +00:00
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
2022-12-21 16:17:53 +00:00
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/icon_widgets/copy_icon.dart';
import 'package:stackwallet/widgets/icon_widgets/qrcode_icon.dart';
import 'package:stackwallet/widgets/icon_widgets/share_icon.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:stackwallet/widgets/toggle.dart';
2022-12-20 23:00:03 +00:00
2022-12-21 23:02:14 +00:00
class PaynymHomeView extends ConsumerStatefulWidget {
2022-12-20 23:00:03 +00:00
const PaynymHomeView({
Key? key,
required this.walletId,
}) : super(key: key);
final String walletId;
static const String routeName = "/paynymHome";
@override
2022-12-21 23:02:14 +00:00
ConsumerState<PaynymHomeView> createState() => _PaynymHomeViewState();
2022-12-20 23:00:03 +00:00
}
2022-12-21 23:02:14 +00:00
class _PaynymHomeViewState extends ConsumerState<PaynymHomeView> {
2022-12-21 16:17:53 +00:00
bool showFollowing = false;
2022-12-21 23:02:14 +00:00
int secretCount = 0;
Timer? timer;
@override
void dispose() {
timer?.cancel();
timer = null;
super.dispose();
}
2022-12-21 16:17:53 +00:00
2022-12-20 23:00:03 +00:00
@override
Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType");
final isDesktop = Util.isDesktop;
return MasterScaffold(
isDesktop: isDesktop,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () {
Navigator.of(context).pop();
},
),
titleSpacing: 0,
title: Text(
"PayNym",
style: STextStyles.navBarTitle(context),
overflow: TextOverflow.ellipsis,
),
2022-12-21 16:17:53 +00:00
actions: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: AspectRatio(
aspectRatio: 1,
child: AppBarIconButton(
icon: SvgPicture.asset(
Assets.svg.circlePlusFilled,
width: 20,
height: 20,
color: Theme.of(context).extension<StackColors>()!.textDark,
),
onPressed: () {
2022-12-21 19:46:50 +00:00
Navigator.of(context).pushNamed(
AddNewPaynymFollowView.routeName,
2022-12-21 23:02:14 +00:00
arguments: widget.walletId,
2022-12-21 19:46:50 +00:00
);
2022-12-21 16:17:53 +00:00
},
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: AspectRatio(
aspectRatio: 1,
child: AppBarIconButton(
icon: SvgPicture.asset(
Assets.svg.circleQuestion,
width: 20,
height: 20,
color: Theme.of(context).extension<StackColors>()!.textDark,
),
onPressed: () {
2022-12-21 19:46:50 +00:00
// todo info ?
2022-12-21 16:17:53 +00:00
},
),
),
),
const SizedBox(
width: 4,
),
],
2022-12-20 23:00:03 +00:00
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
2022-12-21 16:17:53 +00:00
crossAxisAlignment: CrossAxisAlignment.center,
2022-12-20 23:00:03 +00:00
children: [
2022-12-21 23:02:14 +00:00
GestureDetector(
onTap: () {
secretCount++;
if (secretCount > 5) {
debugPrint(
"My Account: ${ref.read(myPaynymAccountStateProvider.state).state}");
debugPrint(
"My Account: ${ref.read(myPaynymAccountStateProvider.state).state!.following}");
secretCount = 0;
}
timer ??= Timer(
const Duration(milliseconds: 1500),
() {
secretCount = 0;
timer = null;
},
);
},
child: PayNymBot(
paymentCodeString: ref
.watch(myPaynymAccountStateProvider.state)
.state!
.codes
.first
.code,
),
2022-12-21 16:17:53 +00:00
),
const SizedBox(
height: 10,
),
Text(
2022-12-21 23:02:14 +00:00
ref.watch(myPaynymAccountStateProvider.state).state!.nymName,
2022-12-21 16:17:53 +00:00
style: STextStyles.desktopMenuItemSelected(context),
),
const SizedBox(
height: 4,
),
Text(
2022-12-21 23:02:14 +00:00
Format.shorten(
ref
.watch(myPaynymAccountStateProvider.state)
.state!
.codes
.first
.code,
12,
5),
2022-12-21 16:17:53 +00:00
style: STextStyles.label(context),
),
const SizedBox(
height: 11,
),
Row(
children: [
Expanded(
child: SecondaryButton(
label: "Copy",
buttonHeight: ButtonHeight.l,
iconSpacing: 4,
icon: CopyIcon(
width: 10,
height: 10,
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
),
2022-12-21 17:08:14 +00:00
onPressed: () async {
await Clipboard.setData(
ClipboardData(
2022-12-21 23:02:14 +00:00
text: ref
.read(myPaynymAccountStateProvider.state)
.state!
.codes
.first
.code,
2022-12-21 17:08:14 +00:00
),
);
unawaited(
showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
iconAsset: Assets.svg.copy,
context: context,
),
);
2022-12-21 16:17:53 +00:00
},
),
),
const SizedBox(
width: 13,
),
Expanded(
child: SecondaryButton(
label: "Share",
buttonHeight: ButtonHeight.l,
iconSpacing: 4,
icon: ShareIcon(
width: 10,
height: 10,
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
),
onPressed: () {
// copy to clipboard
},
),
),
const SizedBox(
width: 13,
),
Expanded(
child: SecondaryButton(
label: "Address",
buttonHeight: ButtonHeight.l,
iconSpacing: 4,
icon: QrCodeIcon(
width: 10,
height: 10,
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
),
onPressed: () {
2022-12-21 17:06:53 +00:00
showDialog<void>(
context: context,
builder: (context) => PaynymQrPopup(
2022-12-21 23:02:14 +00:00
paynymAccount: ref
.read(myPaynymAccountStateProvider.state)
.state!,
2022-12-21 17:06:53 +00:00
),
);
2022-12-21 16:17:53 +00:00
},
),
),
],
),
const SizedBox(
height: 24,
),
SizedBox(
height: 40,
child: Toggle(
onColor: Theme.of(context).extension<StackColors>()!.popupBG,
onText: "Following",
offColor: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
offText: "Followers",
isOn: showFollowing,
onValueChanged: (value) {
setState(() {
showFollowing = value;
});
},
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
),
),
const SizedBox(
height: 16,
),
RoundedWhiteContainer(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Your PayNym contacts will appear here",
style: STextStyles.label(context),
),
],
),
2022-12-20 23:00:03 +00:00
),
],
),
),
),
);
}
}