128 lines
4.5 KiB
Dart
128 lines
4.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:manager_app/app_context.dart';
|
|
import 'package:manager_app/Models/managerContext.dart';
|
|
import 'package:manager_app/Components/check_input_container.dart';
|
|
import 'package:manager_app/Screens/Configurations/Section/SubSection/Parcours/parcours_config.dart';
|
|
|
|
class SectionParcoursConfig extends StatefulWidget {
|
|
final ParcoursDTO initialValue;
|
|
final ValueChanged<ParcoursDTO> onChanged;
|
|
|
|
const SectionParcoursConfig({
|
|
Key? key,
|
|
required this.initialValue,
|
|
required this.onChanged,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_SectionParcoursConfigState createState() => _SectionParcoursConfigState();
|
|
}
|
|
|
|
class _SectionParcoursConfigState extends State<SectionParcoursConfig> {
|
|
late ParcoursDTO parcoursDTO;
|
|
List<SectionDTO> availableMaps = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
parcoursDTO = widget.initialValue;
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => _loadAvailableMaps());
|
|
}
|
|
|
|
Future<void> _loadAvailableMaps() async {
|
|
if (parcoursDTO.configurationId == null || !mounted) return;
|
|
final appContext = Provider.of<AppContext>(context, listen: false);
|
|
final api = (appContext.getContext() as ManagerAppContext).clientAPI!.sectionApi!;
|
|
try {
|
|
final sections = await api.sectionGetFromConfiguration(parcoursDTO.configurationId!);
|
|
if (sections == null || !mounted) return;
|
|
setState(() {
|
|
availableMaps = sections.where((s) => s.type == SectionType.Map).toList();
|
|
});
|
|
} catch (e) {
|
|
// Silently keep empty on error
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// ── Options carte ──
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: CheckInputContainer(
|
|
label: "Afficher la carte",
|
|
isChecked: parcoursDTO.showMap ?? true,
|
|
onChanged: (val) {
|
|
setState(() => parcoursDTO.showMap = val);
|
|
widget.onChanged(parcoursDTO);
|
|
},
|
|
),
|
|
),
|
|
if (parcoursDTO.showMap == true && availableMaps.isNotEmpty)
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text("Carte de base (optionnel)",
|
|
style: TextStyle(fontWeight: FontWeight.w500)),
|
|
DropdownButton<String?>(
|
|
isExpanded: true,
|
|
value: parcoursDTO.baseSectionMapId,
|
|
items: [
|
|
DropdownMenuItem<String?>(
|
|
value: null, child: Text("Aucune")),
|
|
...availableMaps.map((m) => DropdownMenuItem<String?>(
|
|
value: m.id,
|
|
child: Text(m.label ?? m.id ?? ''))),
|
|
],
|
|
onChanged: (val) {
|
|
setState(() => parcoursDTO.baseSectionMapId = val);
|
|
widget.onChanged(parcoursDTO);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// ── Liste des parcours ──
|
|
if (parcoursDTO.id != null)
|
|
SizedBox(
|
|
height: 500,
|
|
child: ParcoursConfig(
|
|
initialValue: parcoursDTO.guidedPaths ?? [],
|
|
parentId: parcoursDTO.id!,
|
|
isEvent: false,
|
|
isParcours: true,
|
|
onChanged: (paths) {
|
|
setState(() => parcoursDTO.guidedPaths = paths);
|
|
widget.onChanged(parcoursDTO);
|
|
},
|
|
),
|
|
)
|
|
else
|
|
Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Text(
|
|
"Sauvegardez d'abord la section pour gérer les parcours.",
|
|
style: TextStyle(fontStyle: FontStyle.italic, color: Colors.grey[600]),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|