mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 00:51:20 +00:00
refactor: Use snackbar to show snapshot id copy notification
This commit is contained in:
parent
ffa985aba2
commit
fe93360870
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import 'dart:async';
|
||||
|
||||
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 StatefulWidget {
|
||||
class SnapshotIdListTile extends StatelessWidget {
|
||||
const SnapshotIdListTile({
|
||||
required this.snapshotId,
|
||||
super.key,
|
||||
|
@ -12,41 +11,20 @@ class SnapshotIdListTile extends StatefulWidget {
|
|||
|
||||
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;
|
||||
});
|
||||
}
|
||||
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(
|
||||
copiedToClipboard
|
||||
? 'basis.copied_to_clipboard'.tr()
|
||||
: 'backup.snapshot_id_title'.tr(),
|
||||
),
|
||||
subtitle: Text(
|
||||
copiedToClipboard ? '' : widget.snapshotId,
|
||||
),
|
||||
title: Text('backup.snapshot_id_title'.tr()),
|
||||
subtitle: Text(snapshotId),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -52,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: [
|
||||
|
@ -160,6 +162,7 @@ class _SnapshotModalState extends State<SnapshotModal> {
|
|||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue