| 1 | import 'package:cake_wallet/entities/new_ui_entities/list_item/list_item_regular_row.dart'; |
| 2 | import 'package:cake_wallet/generated/i18n.dart'; |
| 3 | import 'package:cake_wallet/new-ui/widgets/receive_page/receive_top_bar.dart'; |
| 4 | import 'package:cake_wallet/src/widgets/new_list_row/new_list_section.dart'; |
| 5 | import 'package:cw_core/payment_uris.dart'; |
| 6 | import 'package:flutter/material.dart'; |
| 7 | import 'package:flutter/semantics.dart'; |
| 8 | import 'package:flutter/services.dart'; |
| 9 | |
| 10 | class PayjoinCopyModal extends StatelessWidget { |
| 11 | const PayjoinCopyModal({super.key, required this.uri}); |
| 12 | |
| 13 | final PaymentURI uri; |
| 14 | |
| 15 | @override |
| 16 | Widget build(BuildContext context) { |
| 17 | return Container( |
| 18 | decoration: BoxDecoration( |
| 19 | borderRadius: BorderRadius.vertical(top: Radius.circular(20)), |
| 20 | color: Theme.of(context).colorScheme.surface), |
| 21 | child: SafeArea( |
| 22 | top: false, |
| 23 | child: Column( |
| 24 | mainAxisSize: MainAxisSize.min, |
| 25 | children: [ |
| 26 | ModalTopBar( |
| 27 | title: S.of(context).select_address_to_copy, |
| 28 | leadingIcon: Icon(Icons.close), |
| 29 | leadingSemanticLabel: S.of(context).close, |
| 30 | onLeadingPressed: Navigator.of(context).pop), |
| 31 | Padding( |
| 32 | padding: const EdgeInsets.symmetric(horizontal: 16.0), |
| 33 | child: NewListSections(sections: { |
| 34 | "": [ |
| 35 | ListItemRegularRow( |
| 36 | keyValue: "btc", |
| 37 | label: S.of(context).standard, |
| 38 | iconPath: "assets/new-ui/pjmodal_btc.svg", |
| 39 | onTap: () { |
| 40 | Clipboard.setData( |
| 41 | ClipboardData( |
| 42 | text: uri.amount.isNotEmpty |
| 43 | ? BitcoinURI(amount: uri.amount, address: uri.address).toString() |
| 44 | : uri.address), |
| 45 | ); |
| 46 | _announceCopied(context); |
| 47 | Navigator.of(context).pop(); |
| 48 | }), |
| 49 | ListItemRegularRow( |
| 50 | keyValue: "pj", |
| 51 | label: "Payjoin", |
| 52 | iconPath: "assets/new-ui/pjmodal_pj.svg", |
| 53 | onTap: () { |
| 54 | Clipboard.setData( |
| 55 | ClipboardData(text: uri.toString()), |
| 56 | ); |
| 57 | _announceCopied(context); |
| 58 | Navigator.of(context).pop(); |
| 59 | }) |
| 60 | ] |
| 61 | }), |
| 62 | ), |
| 63 | SizedBox(height: 128) |
| 64 | ], |
| 65 | ), |
| 66 | ), |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | // Copying pops this sheet right away, so no widget survives to carry a |
| 71 | // semantics state change: this path still needs a direct announcement. It is |
| 72 | // skipped on platforms that deprecate announcements (android, where they |
| 73 | // clear TalkBack's speech queue and the system shows its own clipboard |
| 74 | // confirmation anyway). |
| 75 | void _announceCopied(BuildContext context) { |
| 76 | if (!MediaQuery.supportsAnnounceOf(context)) return; |
| 77 | SemanticsService.sendAnnouncement( |
| 78 | View.of(context), S.of(context).copied, Directionality.of(context)); |
| 79 | } |
| 80 | } |