ANDREAS_LATANOWSKY_CPD_1910877/lib/session_list_view.dart

78 lines
2.3 KiB
Dart
Raw Permalink Normal View History

2024-01-10 23:39:33 +01:00
import 'dart:typed_data';
import 'package:cpd_app/file_utils.dart';
import 'package:cpd_app/session_list.dart';
import 'package:flutter/material.dart';
class SessionListView extends StatefulWidget {
const SessionListView({super.key});
@override
State<SessionListView> createState() => _SessionListViewState();
}
class _SessionListViewState extends State<SessionListView> {
final Map<String, Uint8List> _images = ImageList.getImages();
String? _selectedImageKey;
bool _showSaveButton = false;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color.fromARGB(99, 78, 72, 72),
appBar: AppBar(
backgroundColor: const Color.fromARGB(255, 161, 120, 17),
title: const Text('Image Gallery'),
),
body: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0,
),
itemCount: _images.length,
itemBuilder: (BuildContext context, int index) {
String imageKey = _images.keys.elementAt(index);
Uint8List imageData = _images[imageKey]!;
return GestureDetector(
onTap: () {
setState(() {
_selectedImageKey = imageKey;
_showSaveButton = true;
});
},
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: _selectedImageKey == imageKey
? Colors.blue
: Colors.transparent,
width: 2.0,
),
),
child: Image.memory(
imageData,
fit: BoxFit.cover,
),
),
);
},
),
floatingActionButton: _showSaveButton
? FloatingActionButton(
onPressed: () {
saveImage(_selectedImageKey!);
setState(() {
_showSaveButton = false;
});
},
child: const Icon(Icons.save),
)
: null,
);
}
void saveImage(String imageKey) {
FileUtils.saveTranslatedImage(ImageList.getImages()[imageKey]!);
}
}