Merge pull request 'feat: Implement copying to clipboard for snapshot id of backups' (#325) from snapshot-id into master

Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/pulls/325
Reviewed-by: Inex Code <inex.code@selfprivacy.org>
This commit is contained in:
NaiJi ✨ 2023-09-07 23:58:39 +03:00
commit fd13828ec3
3 changed files with 142 additions and 118 deletions

View file

@ -21,11 +21,12 @@ class NavigationService {
);
}
void showSnackBar(final String text) {
void showSnackBar(final String text, {final SnackBarBehavior? behavior}) {
final ScaffoldMessengerState state = scaffoldMessengerKey.currentState!;
final SnackBar snack = SnackBar(
content: Text(text),
duration: const Duration(seconds: 2),
behavior: behavior,
);
state.showSnackBar(snack);
}

View file

@ -0,0 +1,30 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:selfprivacy/config/get_it_config.dart';
class SnapshotIdListTile extends StatelessWidget {
const SnapshotIdListTile({
required this.snapshotId,
super.key,
});
final String snapshotId;
@override
Widget build(final BuildContext context) => ListTile(
onLongPress: () {
Clipboard.setData(ClipboardData(text: snapshotId));
getIt<NavigationService>().showSnackBar(
'basis.copied_to_clipboard'.tr(),
behavior: SnackBarBehavior.floating,
);
},
leading: Icon(
Icons.numbers_outlined,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text('backup.snapshot_id_title'.tr()),
subtitle: Text(snapshotId),
);
}

View file

@ -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/cards/outlined_card.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 {
const SnapshotModal({
@ -51,7 +52,9 @@ class _SnapshotModalState extends State<SnapshotModal> {
.state
.getServiceById(widget.snapshot.serviceId);
return ListView(
return Scaffold(
backgroundColor: Colors.transparent,
body: ListView(
controller: widget.scrollController,
padding: const EdgeInsets.all(16),
children: [
@ -95,18 +98,7 @@ class _SnapshotModalState extends State<SnapshotModal> {
'${MaterialLocalizations.of(context).formatShortDate(widget.snapshot.time)} ${TimeOfDay.fromDateTime(widget.snapshot.time).format(context)}',
),
),
ListTile(
leading: Icon(
Icons.numbers_outlined,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'backup.snapshot_id_title'.tr(),
),
subtitle: Text(
widget.snapshot.id,
),
),
SnapshotIdListTile(snapshotId: widget.snapshot.id),
if (service != null)
Column(
children: [
@ -170,6 +162,7 @@ class _SnapshotModalState extends State<SnapshotModal> {
),
)
],
),
);
}
}