Files
flutter/lib/features/gallery/widgets/overview.dart
Roland Geider 2d9b8cadb6 Reorder imports
dart fix --apply --code=directives_ordering
2026-09-03 20:42:06 +02:00

132 lines
4.2 KiB
Dart

/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (C) 2020, 2021 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wger Workout Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:material_ui/material_ui.dart';
import 'package:wger/core/form_screen.dart';
import 'package:wger/core/formatting/formatting.dart';
import 'package:wger/core/platform.dart';
import 'package:wger/core/widgets/text_prompt.dart';
import 'package:wger/core/widgets/wger_image.dart';
import 'package:wger/features/gallery/models/image.dart';
import 'package:wger/features/gallery/providers/gallery_notifier.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'forms.dart';
class Gallery extends ConsumerWidget {
const Gallery();
@override
Widget build(BuildContext context, WidgetRef ref) {
final images = ref.watch(galleryProvider).value ?? const [];
return Padding(
padding: const EdgeInsets.all(5),
child: images.isEmpty
? const TextPrompt()
: MasonryGridView.count(
crossAxisCount: 2,
mainAxisSpacing: 5,
crossAxisSpacing: 5,
itemCount: images.length,
itemBuilder: (context, index) {
final currentImage = images[index];
return GestureDetector(
onTap: () {
showModalBottomSheet(
builder: (context) => ImageDetail(image: currentImage),
context: context,
);
},
child: WgerImage(
key: Key('image-${currentImage.id!}'),
mediaPath: currentImage.imagePath,
fit: BoxFit.cover,
),
);
},
),
);
}
}
class ImageDetail extends ConsumerWidget {
const ImageDetail({
super.key,
required this.image,
});
final GalleryImage image;
@override
Widget build(BuildContext context, WidgetRef ref) {
return Container(
key: Key('image-${image.id!}-detail'),
padding: const EdgeInsets.all(10),
child: Column(
children: [
Text(
localizedDate(context).format(image.date),
style: Theme.of(context).textTheme.headlineSmall,
),
Expanded(
child: WgerImage(
mediaPath: image.imagePath,
fit: BoxFit.contain,
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Text(image.description),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
icon: const Icon(Icons.delete),
onPressed: () {
ref.read(galleryProvider.notifier).deleteImage(image);
Navigator.of(context).pop();
},
),
if (!isDesktop)
IconButton(
icon: const Icon(Icons.edit),
onPressed: () {
Navigator.pushNamed(
context,
FormScreen.routeName,
arguments: FormScreenArguments(
AppLocalizations.of(context).edit,
ImageForm(image),
hasListView: true,
),
);
},
),
],
),
],
),
);
}
}