Skip to content

Commit

Permalink
CWテキストをコピーできるように
Browse files Browse the repository at this point in the history
  • Loading branch information
Npepperlinux committed Dec 1, 2024
1 parent b01c83c commit 6274039
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
50 changes: 44 additions & 6 deletions lib/view/copy_modal_sheet/copy_note_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:miria/view/themes/app_theme.dart";

class CopyNoteModalSheet extends ConsumerWidget {
final String note;
final String text;
final String? cw;

const CopyNoteModalSheet({
required this.note,
required this.text,
this.cw,
super.key,
});

Expand All @@ -22,10 +24,11 @@ class CopyNoteModalSheet extends ConsumerWidget {
ListTile(
title: Text(S.of(context).detail),
trailing: IconButton(
onPressed: () {
Clipboard.setData(
ClipboardData(text: note),
onPressed: () async {
await Clipboard.setData(
ClipboardData(text: text),
);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(S.of(context).doneCopy),
Expand All @@ -37,11 +40,46 @@ class CopyNoteModalSheet extends ConsumerWidget {
tooltip: S.of(context).copyContents,
),
),
if (cw != null)
Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Card(
child: Padding(
padding: const EdgeInsets.all(10),
child: SelectableText(
cw!,
style: AppTheme.of(context).monospaceStyle,
),
),
),
),
IconButton(
onPressed: () async {
await Clipboard.setData(
ClipboardData(text: cw!),
);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(S.of(context).doneCopy),
duration: const Duration(seconds: 1),
),
);
},
icon: const Icon(Icons.copy),
),
],
),
),
Card(
child: Padding(
padding: const EdgeInsets.all(10),
child: SelectableText(
note,
text,
style: AppTheme.of(context).monospaceStyle,
),
),
Expand Down
3 changes: 2 additions & 1 deletion lib/view/note_modal_sheet/note_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ class NoteModalSheet extends ConsumerWidget implements AutoRouteWrapper {
await showModalBottomSheet(
context: context,
builder: (context) => CopyNoteModalSheet(
note: targetNote.text ?? "",
text: targetNote.text ?? "",
cw: targetNote.cw,
),
);
},
Expand Down

0 comments on commit 6274039

Please sign in to comment.