add copy to clipboard functionality

This commit is contained in:
sneurlax 2023-04-06 11:22:29 -05:00
parent c396d97d85
commit c50d8fc495

View file

@ -1,6 +1,12 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
@ -11,10 +17,13 @@ class DesktopShowXpubDialog extends ConsumerStatefulWidget {
const DesktopShowXpubDialog({
Key? key,
required this.xpub,
this.clipboardInterface = const ClipboardWrapper(),
}) : super(key: key);
final String xpub;
final ClipboardInterface clipboardInterface;
static const String routeName = "/desktopShowXpubDialog";
@override
@ -23,8 +32,11 @@ class DesktopShowXpubDialog extends ConsumerStatefulWidget {
}
class _DesktopShowXpubDialog extends ConsumerState<DesktopShowXpubDialog> {
late ClipboardInterface _clipboardInterface;
@override
void initState() {
_clipboardInterface = widget.clipboardInterface;
super.initState();
}
@ -33,6 +45,16 @@ class _DesktopShowXpubDialog extends ConsumerState<DesktopShowXpubDialog> {
super.dispose();
}
Future<void> _copy() async {
await _clipboardInterface.setData(ClipboardData(text: widget.xpub));
unawaited(showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
iconAsset: Assets.svg.copy,
context: context,
));
}
@override
Widget build(BuildContext context) {
return DesktopDialog(
@ -71,6 +93,14 @@ class _DesktopShowXpubDialog extends ConsumerState<DesktopShowXpubDialog> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
PrimaryButton(
width: 250,
buttonHeight: ButtonHeight.xl,
label: "Copy to clipboard",
onPressed: () async {
await _copy();
}),
const SizedBox(width: 16),
PrimaryButton(
width: 250,
buttonHeight: ButtonHeight.xl,