170 lines
6.5 KiB
Dart
170 lines
6.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/constants.dart';
|
|
import 'package:manager_app/l10n/app_localizations.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) {
|
|
final l = AppLocalizations.of(context)!;
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// ── Où se déroule le parcours ? ──
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(l.parcoursWhereTitle,
|
|
style: TextStyle(fontWeight: FontWeight.w600)),
|
|
RadioGroup<bool>(
|
|
groupValue: parcoursDTO.showMap ?? true,
|
|
onChanged: (val) {
|
|
setState(() => parcoursDTO.showMap = val);
|
|
widget.onChanged(parcoursDTO);
|
|
},
|
|
child: Column(
|
|
children: [
|
|
RadioListTile<bool>(
|
|
dense: true,
|
|
contentPadding: EdgeInsets.zero,
|
|
activeColor: kPrimaryColor,
|
|
value: false,
|
|
title: Text(l.parcoursIndoor, style: TextStyle(fontSize: 14)),
|
|
subtitle: Text(
|
|
l.parcoursIndoorDesc,
|
|
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
|
),
|
|
),
|
|
RadioListTile<bool>(
|
|
dense: true,
|
|
contentPadding: EdgeInsets.zero,
|
|
activeColor: kPrimaryColor,
|
|
value: true,
|
|
title: Text(l.parcoursOutdoor, style: TextStyle(fontSize: 14)),
|
|
subtitle: Text(
|
|
l.parcoursOutdoorDesc,
|
|
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (parcoursDTO.showMap == true)
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(l.parcoursBaseMapOptional,
|
|
style: TextStyle(fontWeight: FontWeight.w500)),
|
|
DropdownButton<String?>(
|
|
isExpanded: true,
|
|
value: parcoursDTO.baseSectionMapId,
|
|
items: [
|
|
DropdownMenuItem<String?>(
|
|
value: null, child: Text(l.noneFeminine)),
|
|
...availableMaps.map((m) => DropdownMenuItem<String?>(
|
|
value: m.id,
|
|
child: Text(m.label ?? m.id ?? ''))),
|
|
],
|
|
onChanged: availableMaps.isEmpty
|
|
? null
|
|
: (val) {
|
|
setState(
|
|
() => parcoursDTO.baseSectionMapId = val);
|
|
widget.onChanged(parcoursDTO);
|
|
},
|
|
),
|
|
if (availableMaps.isEmpty)
|
|
Text(
|
|
l.parcoursNoMapSection,
|
|
style: TextStyle(
|
|
fontSize: 12, color: Colors.grey[600]),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// ── Liste des parcours ──
|
|
if (parcoursDTO.id != null)
|
|
ParcoursConfig(
|
|
initialValue: parcoursDTO.guidedPaths ?? [],
|
|
parentId: parcoursDTO.id!,
|
|
isEvent: false,
|
|
isParcours: true,
|
|
isGeolocated: parcoursDTO.showMap ?? true,
|
|
onChanged: (paths) {
|
|
setState(() => parcoursDTO.guidedPaths = paths);
|
|
widget.onChanged(parcoursDTO);
|
|
},
|
|
)
|
|
else
|
|
Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Text(
|
|
l.parcoursSaveSectionFirst,
|
|
style: TextStyle(fontStyle: FontStyle.italic, color: Colors.grey[600]),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|