Files
flutter/lib/widgets/gallery/overview.dart
Roland Geider cbf6884a30 Update the online connectivity gates
Some of these models can now be edited completely locally, others only partly
(e.g. the gallery entries can only be created online)
2026-05-20 14:14:00 +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/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:intl/intl.dart';
import 'package:wger/helpers/platform.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/models/gallery/image.dart';
import 'package:wger/providers/gallery_notifier.dart';
import 'package:wger/screens/form_screen.dart';
import 'package:wger/widgets/core/text_prompt.dart';
import 'package:wger/widgets/core/wger_image.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(
DateFormat.yMd(Localizations.localeOf(context).languageCode).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,
),
);
},
),
],
),
],
),
);
}
}