247 lines
8.9 KiB
Dart
247 lines
8.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:manager_app/Components/check_input_container.dart';
|
|
import 'package:manager_app/Components/multi_string_input_container.dart';
|
|
import 'package:manager_app/Components/single_select_container.dart';
|
|
import 'showNewOrUpdateEventAgenda.dart';
|
|
|
|
class AgendaConfig extends StatefulWidget {
|
|
final String? color;
|
|
final String? label;
|
|
final AgendaDTO initialValue;
|
|
final ValueChanged<AgendaDTO> onChanged;
|
|
|
|
const AgendaConfig({
|
|
Key? key,
|
|
this.color,
|
|
this.label,
|
|
required this.initialValue,
|
|
required this.onChanged,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_AgendaConfigState createState() => _AgendaConfigState();
|
|
}
|
|
|
|
class _AgendaConfigState extends State<AgendaConfig> {
|
|
late AgendaDTO agendaDTO;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
agendaDTO = widget.initialValue;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
var mapProviderIn = "";
|
|
switch (agendaDTO.agendaMapProvider) {
|
|
case MapProvider.Google:
|
|
mapProviderIn = "Google";
|
|
break;
|
|
case MapProvider.MapBox:
|
|
mapProviderIn = "MapBox";
|
|
break;
|
|
default:
|
|
mapProviderIn = "Google";
|
|
break;
|
|
}
|
|
|
|
return Column(
|
|
children: [
|
|
_buildAgendaHeader(size, mapProviderIn),
|
|
if (agendaDTO.isOnlineAgenda == false) ...[
|
|
const Divider(height: 32),
|
|
Padding(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
const Text("Évènements Manuels",
|
|
style:
|
|
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
|
ElevatedButton.icon(
|
|
icon: const Icon(Icons.add),
|
|
label: const Text("Ajouter un évènement"),
|
|
onPressed: () {
|
|
showNewOrUpdateEventAgenda(
|
|
context,
|
|
null,
|
|
agendaDTO.id ?? "temp",
|
|
(newEvent) {
|
|
setState(() {
|
|
agendaDTO.events = [
|
|
...(agendaDTO.events ?? []),
|
|
newEvent
|
|
];
|
|
widget.onChanged(agendaDTO);
|
|
});
|
|
},
|
|
);
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: kSuccess,
|
|
foregroundColor: kWhite,
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16, vertical: 12),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
height: 600,
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
child: (agendaDTO.events == null || agendaDTO.events!.isEmpty)
|
|
? const Center(
|
|
child: Text("Aucun évènement manuel",
|
|
style: TextStyle(fontStyle: FontStyle.italic)))
|
|
: ListView.builder(
|
|
itemCount: agendaDTO.events!.length,
|
|
itemBuilder: (context, index) {
|
|
final event = agendaDTO.events![index];
|
|
return Card(
|
|
elevation: 2,
|
|
margin: const EdgeInsets.symmetric(
|
|
horizontal: 16, vertical: 6),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
child: ListTile(
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 16, vertical: 8),
|
|
leading: CircleAvatar(
|
|
backgroundColor: kPrimaryColor.withOpacity(0.1),
|
|
child:
|
|
const Icon(Icons.event, color: kPrimaryColor),
|
|
),
|
|
title: Text(
|
|
(event.label != null && event.label!.isNotEmpty)
|
|
? (event.label!.firstWhere(
|
|
(t) => t.language == 'FR',
|
|
orElse: () => event.label![0])).value!
|
|
: "Évènement $index",
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
subtitle: Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child:
|
|
Text(event.address?.address ?? "Pas d'adresse"),
|
|
),
|
|
trailing: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.edit,
|
|
color: kPrimaryColor),
|
|
onPressed: () {
|
|
showNewOrUpdateEventAgenda(
|
|
context,
|
|
event,
|
|
agendaDTO.id ?? "temp",
|
|
(updatedEvent) {
|
|
setState(() {
|
|
agendaDTO.events![index] = updatedEvent;
|
|
widget.onChanged(agendaDTO);
|
|
});
|
|
},
|
|
);
|
|
},
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.delete, color: kError),
|
|
onPressed: () {
|
|
setState(() {
|
|
agendaDTO.events!.removeAt(index);
|
|
widget.onChanged(agendaDTO);
|
|
});
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildAgendaHeader(Size size, String mapProviderIn) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(16.0),
|
|
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(15),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.1),
|
|
spreadRadius: 2,
|
|
blurRadius: 5,
|
|
offset: const Offset(0, 3),
|
|
),
|
|
],
|
|
border: Border.all(color: kPrimaryColor.withOpacity(0.2)),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
CheckInputContainer(
|
|
label: "En ligne :",
|
|
isChecked: agendaDTO.isOnlineAgenda ?? true,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
agendaDTO.isOnlineAgenda = value;
|
|
widget.onChanged(agendaDTO);
|
|
});
|
|
},
|
|
),
|
|
SingleSelectContainer(
|
|
label: "Service carte :",
|
|
color: Colors.black,
|
|
initialValue: mapProviderIn,
|
|
inputValues: const ["Google", "MapBox"],
|
|
onChanged: (String value) {
|
|
setState(() {
|
|
switch (value) {
|
|
case "Google":
|
|
agendaDTO.agendaMapProvider = MapProvider.Google;
|
|
break;
|
|
case "MapBox":
|
|
agendaDTO.agendaMapProvider = MapProvider.MapBox;
|
|
break;
|
|
}
|
|
widget.onChanged(agendaDTO);
|
|
});
|
|
},
|
|
),
|
|
if (agendaDTO.isOnlineAgenda == true)
|
|
MultiStringInputContainer(
|
|
label: "Fichiers json :",
|
|
resourceTypes: const [ResourceType.Json, ResourceType.JsonUrl],
|
|
modalLabel: "JSON",
|
|
color: kPrimaryColor,
|
|
initialValue: agendaDTO.resourceIds ?? [],
|
|
isTitle: false,
|
|
onGetResult: (value) {
|
|
setState(() {
|
|
agendaDTO.resourceIds = value;
|
|
widget.onChanged(agendaDTO);
|
|
});
|
|
},
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|