action_bar_widget.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/core/configuration.dart';
  3. import "package:photos/generated/l10n.dart";
  4. import 'package:photos/models/selected_files.dart';
  5. import 'package:photos/theme/ente_theme.dart';
  6. class ActionBarWidget extends StatefulWidget {
  7. final SelectedFiles? selectedFiles;
  8. final VoidCallback? onCancel;
  9. const ActionBarWidget({
  10. required this.onCancel,
  11. this.selectedFiles,
  12. super.key,
  13. });
  14. @override
  15. State<ActionBarWidget> createState() => _ActionBarWidgetState();
  16. }
  17. class _ActionBarWidgetState extends State<ActionBarWidget> {
  18. final ValueNotifier<int> _selectedFilesNotifier = ValueNotifier(0);
  19. final ValueNotifier<int> _selectedOwnedFilesNotifier = ValueNotifier(0);
  20. final int currentUserID = Configuration.instance.getUserID()!;
  21. @override
  22. void initState() {
  23. widget.selectedFiles?.addListener(_selectedFilesListener);
  24. super.initState();
  25. }
  26. @override
  27. void dispose() {
  28. _selectedFilesNotifier.dispose();
  29. _selectedOwnedFilesNotifier.dispose();
  30. widget.selectedFiles?.removeListener(_selectedFilesListener);
  31. super.dispose();
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. final textTheme = getEnteTextTheme(context);
  36. return SizedBox(
  37. child: Padding(
  38. padding: const EdgeInsets.fromLTRB(20, 8, 20, 8),
  39. child: Row(
  40. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  41. children: [
  42. Flexible(
  43. flex: 1,
  44. child: ValueListenableBuilder(
  45. valueListenable: _selectedFilesNotifier,
  46. builder: (context, value, child) {
  47. return Text(
  48. _selectedOwnedFilesNotifier.value !=
  49. _selectedFilesNotifier.value
  50. ? S.of(context).selectedPhotosWithYours(
  51. _selectedFilesNotifier.value,
  52. _selectedOwnedFilesNotifier.value,
  53. )
  54. : S.of(context).selectedPhotos(
  55. _selectedFilesNotifier.value,
  56. ),
  57. style: textTheme.miniMuted,
  58. );
  59. },
  60. ),
  61. ),
  62. Flexible(
  63. flex: 1,
  64. child: Padding(
  65. padding: const EdgeInsets.symmetric(vertical: 12),
  66. child: GestureDetector(
  67. behavior: HitTestBehavior.opaque,
  68. onTap: () {
  69. widget.onCancel?.call();
  70. },
  71. child: Align(
  72. alignment: Alignment.centerRight,
  73. child: Text(
  74. S.of(context).cancel,
  75. style: textTheme.mini,
  76. ),
  77. ),
  78. ),
  79. ),
  80. ),
  81. ],
  82. ),
  83. ),
  84. );
  85. }
  86. void _selectedFilesListener() {
  87. if (widget.selectedFiles!.files.isNotEmpty) {
  88. _selectedFilesNotifier.value = widget.selectedFiles!.files.length;
  89. _selectedOwnedFilesNotifier.value = widget.selectedFiles!.files
  90. .where((f) => f.ownerID == null || f.ownerID! == currentUserID)
  91. .length;
  92. }
  93. }
  94. }