182 lines
5.5 KiB
Dart
182 lines
5.5 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_bloc.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_event.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/detail/model/note.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/detail/presentation/note/note_add_dialog.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/detail/presentation/note/note_image_overview.dart';
|
|
import 'package:hl_lieferservice/feature/delivery/detail/presentation/note/note_list.dart';
|
|
import 'package:hl_lieferservice/model/delivery.dart';
|
|
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
|
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
enum NoteAction {
|
|
addNote,
|
|
addImage
|
|
}
|
|
|
|
class NoteOverview extends StatefulWidget {
|
|
final List<NoteInformation> notes;
|
|
final List<NoteTemplate> templates;
|
|
final List<ImageNote> images;
|
|
final String deliveryId;
|
|
|
|
const NoteOverview({
|
|
super.key,
|
|
required this.notes,
|
|
required this.deliveryId,
|
|
required this.templates,
|
|
required this.images,
|
|
});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _NoteOverviewState();
|
|
}
|
|
|
|
class _NoteOverviewState extends State<NoteOverview> {
|
|
final _imagePicker = ImagePicker();
|
|
|
|
Widget _notes() {
|
|
for (final note in widget.notes) {
|
|
debugPrint("Note: ${note.note.content}");
|
|
debugPrint("NOTE Article: ${note.article?.name.toString()}");
|
|
}
|
|
|
|
return NoteList(notes: widget.notes, deliveryId: widget.deliveryId);
|
|
}
|
|
|
|
Widget _images() {
|
|
return NoteImageOverview(
|
|
images: widget.images,
|
|
deliveryId: widget.deliveryId,
|
|
);
|
|
}
|
|
|
|
void _onAddNote(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (_) {
|
|
return BlocProvider.value(value: context.read<NoteBloc>(), child: NoteAddDialog(
|
|
delivery: widget.deliveryId,
|
|
templates: widget.templates,
|
|
));
|
|
},
|
|
);
|
|
}
|
|
|
|
void _onAddImage(BuildContext context) async {
|
|
XFile? file = await _imagePicker.pickImage(source: ImageSource.camera);
|
|
if (file == null) {
|
|
context.read<OperationBloc>().add(
|
|
FailOperation(message: "Fehler beim Aufnehmen des Bildes"),
|
|
);
|
|
return;
|
|
}
|
|
|
|
context.read<NoteBloc>().add(
|
|
AddImageNote(file: file, deliveryId: widget.deliveryId),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(10),
|
|
child: ListView(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
child: Text(
|
|
"Notizen",
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
|
),
|
|
),
|
|
_notes(),
|
|
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 10, top: 10),
|
|
child: Text(
|
|
"Bilder",
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
|
),
|
|
),
|
|
|
|
_images(),
|
|
],
|
|
),
|
|
),
|
|
|
|
Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(right: 25),
|
|
child: PopupMenuButton<NoteAction>(
|
|
onSelected: (NoteAction action) {
|
|
switch (action) {
|
|
case NoteAction.addNote:
|
|
_onAddNote(context);
|
|
break;
|
|
case NoteAction.addImage:
|
|
_onAddImage(context);
|
|
break;
|
|
}
|
|
},
|
|
itemBuilder: (_) {
|
|
return [
|
|
PopupMenuItem<NoteAction>(
|
|
value: NoteAction.addNote,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.note_add_rounded,
|
|
color: Theme.of(context).primaryColor,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 10),
|
|
child: const Text("Notiz hinzufügen"),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
PopupMenuItem<NoteAction>(
|
|
value: NoteAction.addImage,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.image,
|
|
color: Theme.of(context).primaryColor,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 10),
|
|
child: const Text("Bild hochladen"),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
];
|
|
},
|
|
style: ButtonStyle(
|
|
backgroundColor: WidgetStatePropertyAll(
|
|
Theme.of(context).primaryColor,
|
|
),
|
|
),
|
|
child: CircleAvatar(
|
|
radius: 32,
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
child: Icon(
|
|
Icons.add,
|
|
color: Theme.of(context).colorScheme.onSecondary,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|