102 lines
4.3 KiB
Dart
102 lines
4.3 KiB
Dart
import 'package:carousel_slider/carousel_slider.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:stadtbote/model/task_info.dart';
|
|
import 'package:stadtbote/tools/util.dart';
|
|
|
|
Future<void> showTakePhotosPopup(BuildContext context, TaskInfo taskInfo, Function() onFinished) async {
|
|
List<Uint8List> imageDataList = [];
|
|
List<Widget> imageWidgetsList = [];
|
|
|
|
ValueNotifier<List<Widget>> imageWidgetsListNotifier = ValueNotifier<List<Widget>>([]);
|
|
|
|
await showDialog<void>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
contentPadding: EdgeInsets.zero,
|
|
shadowColor: Colors.transparent,
|
|
backgroundColor: Colors.white,
|
|
content: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
|
void capturePhoto() async {
|
|
var photo = await Util.capturePhoto();
|
|
|
|
if (photo != null) {
|
|
var imageData = await photo.readAsBytes();
|
|
photo.delete();
|
|
|
|
imageDataList.add(imageData);
|
|
|
|
imageWidgetsList.add(GestureDetector(
|
|
onTap: () {},
|
|
child: Image.memory(imageData),
|
|
));
|
|
|
|
imageWidgetsListNotifier.value = imageWidgetsList;
|
|
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
return SizedBox(
|
|
key: GlobalKey(),
|
|
height: 545,
|
|
width: MediaQuery.of(context).size.width * 0.8,
|
|
child: Container(
|
|
height: 100,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(10),
|
|
color: Colors.white,
|
|
border: Border.all(
|
|
color: Colors.grey,
|
|
width: 0.5,
|
|
),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(35.0),
|
|
child: Column(
|
|
children: [
|
|
const Text('Aufgenommene Fotos'),
|
|
const SizedBox(height: 20),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(10),
|
|
color: Colors.white,
|
|
border: Border.all(
|
|
color: Colors.grey,
|
|
width: 0.5,
|
|
),
|
|
),
|
|
height: 300,
|
|
child: ValueListenableBuilder<List<Widget>>(
|
|
valueListenable: imageWidgetsListNotifier,
|
|
builder: (context, value, child) {
|
|
return CarouselSlider(
|
|
options: CarouselOptions(
|
|
disableCenter: false,
|
|
enableInfiniteScroll: false,
|
|
),
|
|
items: imageWidgetsList.toList());
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
Visibility(visible: imageDataList.length < taskInfo.task.max!, child: getDefaultButton('Hinzufügen', buttonHeight: 50, () => {capturePhoto()})),
|
|
const SizedBox(height: 12),
|
|
getDefaultButton(
|
|
'Übernehmen',
|
|
buttonHeight: 50,
|
|
() => {
|
|
if (imageDataList.length == taskInfo.task.min! && imageDataList.length <= taskInfo.task.max!)
|
|
{Navigator.of(context).pop(), onFinished()}
|
|
else
|
|
{showAlertDialog(context, 'Fehler', 'Sie müssen mindestens ${taskInfo.task.min} Foto(s) aufnehmen')}
|
|
})
|
|
],
|
|
),
|
|
),
|
|
));
|
|
}));
|
|
});
|
|
}
|