mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 00:51:20 +00:00
feat: Implement copying to clipboard for snapshot id of backups
This commit is contained in:
parent
c5671cc767
commit
ffa985aba2
52
lib/ui/pages/backups/snapshot_id_list_tile.dart
Normal file
52
lib/ui/pages/backups/snapshot_id_list_tile.dart
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
class SnapshotIdListTile extends StatefulWidget {
|
||||||
|
const SnapshotIdListTile({
|
||||||
|
required this.snapshotId,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String snapshotId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SnapshotIdListTile> createState() => _SnapshotIdListTileState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SnapshotIdListTileState extends State<SnapshotIdListTile> {
|
||||||
|
bool copiedToClipboard = false;
|
||||||
|
|
||||||
|
void handleTimeout() {
|
||||||
|
setState(() {
|
||||||
|
copiedToClipboard = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(final BuildContext context) => ListTile(
|
||||||
|
onLongPress: () {
|
||||||
|
if (copiedToClipboard == false) {
|
||||||
|
Clipboard.setData(ClipboardData(text: widget.snapshotId));
|
||||||
|
Timer(const Duration(seconds: 2), handleTimeout);
|
||||||
|
setState(() {
|
||||||
|
copiedToClipboard = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
leading: Icon(
|
||||||
|
Icons.numbers_outlined,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
copiedToClipboard
|
||||||
|
? 'basis.copied_to_clipboard'.tr()
|
||||||
|
: 'backup.snapshot_id_title'.tr(),
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
copiedToClipboard ? '' : widget.snapshotId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import 'package:selfprivacy/logic/models/service.dart';
|
||||||
import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
|
import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/cards/outlined_card.dart';
|
import 'package:selfprivacy/ui/components/cards/outlined_card.dart';
|
||||||
import 'package:selfprivacy/ui/components/info_box/info_box.dart';
|
import 'package:selfprivacy/ui/components/info_box/info_box.dart';
|
||||||
|
import 'package:selfprivacy/ui/pages/backups/snapshot_id_list_tile.dart';
|
||||||
|
|
||||||
class SnapshotModal extends StatefulWidget {
|
class SnapshotModal extends StatefulWidget {
|
||||||
const SnapshotModal({
|
const SnapshotModal({
|
||||||
|
@ -95,18 +96,7 @@ class _SnapshotModalState extends State<SnapshotModal> {
|
||||||
'${MaterialLocalizations.of(context).formatShortDate(widget.snapshot.time)} ${TimeOfDay.fromDateTime(widget.snapshot.time).format(context)}',
|
'${MaterialLocalizations.of(context).formatShortDate(widget.snapshot.time)} ${TimeOfDay.fromDateTime(widget.snapshot.time).format(context)}',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ListTile(
|
SnapshotIdListTile(snapshotId: widget.snapshot.id),
|
||||||
leading: Icon(
|
|
||||||
Icons.numbers_outlined,
|
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
title: Text(
|
|
||||||
'backup.snapshot_id_title'.tr(),
|
|
||||||
),
|
|
||||||
subtitle: Text(
|
|
||||||
widget.snapshot.id,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (service != null)
|
if (service != null)
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
|
|
Loading…
Reference in a new issue