|
1 |
| -import 'dart:ui'; |
| 1 | +import 'dart:ui'; |
2 | 2 |
|
3 | 3 | import 'package:camelus/config/palette.dart';
|
4 | 4 | import 'package:camelus/helpers/nevent_helper.dart';
|
5 | 5 | import 'package:camelus/domain_layer/entities/nostr_note.dart';
|
6 | 6 | import 'package:flutter/material.dart';
|
7 | 7 | import 'package:flutter/services.dart';
|
8 | 8 |
|
| 9 | +/// Copies the given [data] to the system clipboard. |
9 | 10 | Future<void> _copyToClipboard(String data) async {
|
10 | 11 | await Clipboard.setData(ClipboardData(text: data));
|
11 | 12 | }
|
12 | 13 |
|
13 |
| -void openBottomSheetShare(context, NostrNote note) { |
| 14 | + |
| 15 | +void openBottomSheetShare(BuildContext context, NostrNote note) { |
14 | 16 | showModalBottomSheet(
|
15 |
| - isScrollControlled: false, |
16 |
| - elevation: 10, |
17 |
| - backgroundColor: Palette.background, |
18 |
| - isDismissible: true, |
19 |
| - enableDrag: true, |
20 |
| - context: context, |
21 |
| - builder: (ctx) => BackdropFilter( |
22 |
| - filter: ImageFilter.blur(sigmaX: 2, sigmaY: 2), |
23 |
| - child: Padding( |
24 |
| - padding: const EdgeInsets.only(bottom: 20), |
25 |
| - child: Container( |
26 |
| - padding: const EdgeInsets.all(20), |
27 |
| - child: Column( |
28 |
| - mainAxisSize: MainAxisSize.min, |
29 |
| - crossAxisAlignment: CrossAxisAlignment.start, |
| 17 | + isScrollControlled: false, // Prevents the bottom sheet from taking the full screen. |
| 18 | + elevation: 10, |
| 19 | + backgroundColor: Palette.background, // Sets the background color. |
| 20 | + isDismissible: true, // Allows the user to dismiss the bottom sheet by tapping outside. |
| 21 | + enableDrag: true, // Enables the bottom sheet to be dismissed via drag. |
| 22 | + context: context, |
| 23 | + builder: (ctx) => BackdropFilter( |
| 24 | + filter: ImageFilter.blur(sigmaX: 2, sigmaY: 2), |
| 25 | + child: Padding( |
| 26 | + padding: const EdgeInsets.only(bottom: 20), |
| 27 | + child: Container( |
| 28 | + padding: const EdgeInsets.all(20), |
| 29 | + child: Column( |
| 30 | + mainAxisSize: MainAxisSize.min, |
| 31 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 32 | + children: [ |
| 33 | + // Title of the share sheet. |
| 34 | + const Text( |
| 35 | + "share post", |
| 36 | + style: TextStyle(color: Palette.white, fontSize: 30), |
| 37 | + ), |
| 38 | + const SizedBox(height: 20), // Adds vertical spacing. |
| 39 | + Row( |
| 40 | + children: [ |
| 41 | + Column( |
30 | 42 | children: [
|
| 43 | + IconButton( |
| 44 | + tooltip: 'nevent', |
| 45 | + onPressed: () { |
| 46 | + // Generates the bech32 nevent identifier and copies it to the clipboard. |
| 47 | + var bech32nevent = NeventHelper().mapToBech32({ |
| 48 | + "eventId": note.id, // Note's event ID. |
| 49 | + "authorPubkey": note.pubkey, |
| 50 | + "relays": note |
| 51 | + .relayHints, |
| 52 | + }); |
| 53 | + _copyToClipboard(bech32nevent); |
| 54 | + }, |
| 55 | + icon: const Icon( |
| 56 | + Icons.copy, |
| 57 | + color: Palette.white, |
| 58 | + ), |
| 59 | + ), |
| 60 | + |
31 | 61 | const Text(
|
32 |
| - "share post", |
33 |
| - style: TextStyle(color: Palette.white, fontSize: 30), |
| 62 | + "nevent", |
| 63 | + style: TextStyle(color: Palette.lightGray, fontSize: 17), |
34 | 64 | ),
|
35 |
| - const SizedBox(height: 20), |
36 |
| - Row( |
37 |
| - children: [ |
38 |
| - Column( |
39 |
| - children: [ |
40 |
| - IconButton( |
41 |
| - tooltip: 'nevent', |
42 |
| - onPressed: () { |
43 |
| - var bech32nevent = |
44 |
| - NeventHelper().mapToBech32({ |
45 |
| - "eventId": note.id, |
46 |
| - "authorPubkey": note.pubkey, |
47 |
| - "relays": note |
48 |
| - .relayHints, //! todo add relay hints from tracker |
49 |
| - }); |
50 |
| - _copyToClipboard(bech32nevent); |
51 |
| - }, |
52 |
| - icon: const Icon( |
53 |
| - Icons.copy, |
54 |
| - color: Palette.white, |
55 |
| - ), |
56 |
| - ), |
57 |
| - const Text("nevent", |
58 |
| - style: TextStyle( |
59 |
| - color: Palette.lightGray, fontSize: 17)), |
60 |
| - ], |
61 |
| - ), |
62 |
| - const SizedBox(width: 20), |
63 |
| - Column( |
64 |
| - children: [ |
65 |
| - IconButton( |
66 |
| - tooltip: 'njump.me', |
67 |
| - onPressed: () { |
68 |
| - var bech32nevent = |
69 |
| - NeventHelper().mapToBech32({ |
70 |
| - "eventId": note.id, |
71 |
| - "authorPubkey": note.pubkey, |
72 |
| - "relays": note.relayHints, |
73 |
| - }); |
74 |
| - _copyToClipboard( |
75 |
| - 'https://njump.me/$bech32nevent'); |
76 |
| - }, |
77 |
| - icon: const Icon( |
78 |
| - Icons.link, |
79 |
| - color: Palette.white, |
80 |
| - ), |
81 |
| - ), |
82 |
| - const Text("web link", |
83 |
| - style: TextStyle( |
84 |
| - color: Palette.lightGray, fontSize: 17)), |
85 |
| - ], |
86 |
| - ) |
87 |
| - ], |
| 65 | + ], |
| 66 | + ), |
| 67 | + const SizedBox(width: 20), // Adds horizontal spacing. |
| 68 | + |
| 69 | + // Column for the "web link" share option. |
| 70 | + Column( |
| 71 | + children: [ |
| 72 | + IconButton( |
| 73 | + tooltip: 'njump.me', // Tooltip for the button. |
| 74 | + onPressed: () { |
| 75 | + // Generates the bech32 nevent identifier and creates a web link. |
| 76 | + var bech32nevent = NeventHelper().mapToBech32({ |
| 77 | + "eventId": note.id, // Note's event ID. |
| 78 | + "authorPubkey": note.pubkey, // Note's author public key. |
| 79 | + "relays": note.relayHints, // Relays for the note. |
| 80 | + }); |
| 81 | + _copyToClipboard('https://njump.me/$bech32nevent'); |
| 82 | + }, |
| 83 | + icon: const Icon( |
| 84 | + Icons.link, |
| 85 | + color: Palette.white, |
| 86 | + ), |
| 87 | + ), |
| 88 | + const Text( |
| 89 | + "web link", |
| 90 | + style: TextStyle(color: Palette.lightGray, fontSize: 17), |
88 | 91 | ),
|
89 |
| - const SizedBox(height: 20), |
90 | 92 | ],
|
91 | 93 | ),
|
92 |
| - )), |
93 |
| - )); |
| 94 | + ], |
| 95 | + ), |
| 96 | + const SizedBox(height: 20), // Adds vertical spacing. |
| 97 | + ], |
| 98 | + ), |
| 99 | + ), |
| 100 | + ), |
| 101 | + ), |
| 102 | + ); |
94 | 103 | }
|
0 commit comments