mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 17:11:14 +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 ScaffoldMessengerState state = scaffoldMessengerKey.currentState!;
|
||||||
final SnackBar snack = SnackBar(
|
final SnackBar snack = SnackBar(
|
||||||
content: Text(text),
|
content: Text(text),
|
||||||
duration: const Duration(seconds: 2),
|
duration: const Duration(seconds: 2),
|
||||||
|
behavior: behavior,
|
||||||
);
|
);
|
||||||
state.showSnackBar(snack);
|
state.showSnackBar(snack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
|
|
||||||
class SnapshotIdListTile extends StatefulWidget {
|
class SnapshotIdListTile extends StatelessWidget {
|
||||||
const SnapshotIdListTile({
|
const SnapshotIdListTile({
|
||||||
required this.snapshotId,
|
required this.snapshotId,
|
||||||
super.key,
|
super.key,
|
||||||
|
@ -12,41 +11,20 @@ class SnapshotIdListTile extends StatefulWidget {
|
||||||
|
|
||||||
final String snapshotId;
|
final String snapshotId;
|
||||||
|
|
||||||
@override
|
|
||||||
State<SnapshotIdListTile> createState() => _SnapshotIdListTileState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SnapshotIdListTileState extends State<SnapshotIdListTile> {
|
|
||||||
bool copiedToClipboard = false;
|
|
||||||
|
|
||||||
void handleTimeout() {
|
|
||||||
setState(() {
|
|
||||||
copiedToClipboard = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(final BuildContext context) => ListTile(
|
Widget build(final BuildContext context) => ListTile(
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
if (copiedToClipboard == false) {
|
Clipboard.setData(ClipboardData(text: snapshotId));
|
||||||
Clipboard.setData(ClipboardData(text: widget.snapshotId));
|
getIt<NavigationService>().showSnackBar(
|
||||||
Timer(const Duration(seconds: 2), handleTimeout);
|
'basis.copied_to_clipboard'.tr(),
|
||||||
setState(() {
|
behavior: SnackBarBehavior.floating,
|
||||||
copiedToClipboard = true;
|
);
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
leading: Icon(
|
leading: Icon(
|
||||||
Icons.numbers_outlined,
|
Icons.numbers_outlined,
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
),
|
),
|
||||||
title: Text(
|
title: Text('backup.snapshot_id_title'.tr()),
|
||||||
copiedToClipboard
|
subtitle: Text(snapshotId),
|
||||||
? 'basis.copied_to_clipboard'.tr()
|
|
||||||
: 'backup.snapshot_id_title'.tr(),
|
|
||||||
),
|
|
||||||
subtitle: Text(
|
|
||||||
copiedToClipboard ? '' : widget.snapshotId,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,9 @@ class _SnapshotModalState extends State<SnapshotModal> {
|
||||||
.state
|
.state
|
||||||
.getServiceById(widget.snapshot.serviceId);
|
.getServiceById(widget.snapshot.serviceId);
|
||||||
|
|
||||||
return ListView(
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
body: ListView(
|
||||||
controller: widget.scrollController,
|
controller: widget.scrollController,
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
children: [
|
children: [
|
||||||
|
@ -160,6 +162,7 @@ class _SnapshotModalState extends State<SnapshotModal> {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue