Thomas Fransolet d47dc15688 Fix Menu + misc
2025-05-27 15:04:20 +02:00

161 lines
5.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:manager_app/Components/message_notification.dart';
import 'package:manager_app/Components/multi_string_input_and_resource_container.dart';
import 'package:manager_app/Components/number_input_container.dart';
import 'package:manager_app/Components/resource_input_container.dart';
import 'package:manager_api_new/api.dart';
import 'dart:convert';
import 'package:manager_app/constants.dart';
class PuzzleConfig extends StatefulWidget {
final String? color;
final String? label;
final PuzzleDTO initialValue;
final ValueChanged<PuzzleDTO> onChanged;
const PuzzleConfig({
Key? key,
this.color,
this.label,
required this.initialValue,
required this.onChanged,
}) : super(key: key);
@override
_PuzzleConfigState createState() => _PuzzleConfigState();
}
class _PuzzleConfigState extends State<PuzzleConfig> {
late PuzzleDTO puzzleDTO;
@override
void initState() {
PuzzleDTO test = widget.initialValue;
/*if(test.puzzleImage == null) {
test.puzzleImage = ResourceDTO();
}*/
puzzleDTO = test;
puzzleDTO.rows = puzzleDTO.rows == null ? 3 : puzzleDTO.rows;
puzzleDTO.cols = puzzleDTO.cols == null ? 3 : puzzleDTO.cols;
super.initState();
}
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ResourceInputContainer(
label: "Image du puzzle :",
initialValue: puzzleDTO.puzzleImageId == null ? '': puzzleDTO.puzzleImageId,
onChanged: (ResourceDTO resourceDTO) {
setState(() {
if(resourceDTO.id == null)
{
puzzleDTO.puzzleImageId = null;
puzzleDTO.puzzleImage = null;
} else {
puzzleDTO.puzzleImageId = resourceDTO.id;
puzzleDTO.puzzleImage = resourceDTO;
}
widget.onChanged(puzzleDTO);
});
}
),
Container(
height: 100,
child: MultiStringInputAndResourceContainer(
label: "Message départ :",
modalLabel: "Message départ",
fontSize: 20,
color: kPrimaryColor,
initialValue: puzzleDTO.messageDebut != null ? puzzleDTO.messageDebut! : [],
resourceTypes: [ResourceType.Image, ResourceType.ImageUrl, ResourceType.VideoUrl, ResourceType.Video, ResourceType.Audio],
onGetResult: (value) {
if (puzzleDTO.messageDebut != value) {
setState(() {
puzzleDTO.messageDebut = value;
widget.onChanged(puzzleDTO);
});
}
},
maxLines: 1,
isTitle: false
)
),
Container(
height: 100,
child: MultiStringInputAndResourceContainer(
label: "Message fin :",
modalLabel: "Message fin",
fontSize: 20,
color: kPrimaryColor,
initialValue: puzzleDTO.messageFin != null ? puzzleDTO.messageFin! : [],
resourceTypes: [ResourceType.Image, ResourceType.ImageUrl, ResourceType.VideoUrl, ResourceType.Video, ResourceType.Audio],
onGetResult: (value) {
if (puzzleDTO.messageFin != value) {
setState(() {
puzzleDTO.messageFin = value;
widget.onChanged(puzzleDTO);
});
}
},
maxLines: 1,
isTitle: false
)
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 100,
child: NumberInputContainer(
label: "Nombre de lignes :",
initialValue: puzzleDTO.rows!,
isSmall: true,
maxLength: 2,
onChanged: (value) {
try {
puzzleDTO.rows = int.parse(value);
setState(() {
widget.onChanged(puzzleDTO);
});
} catch (e) {
showNotification(Colors.orange, kWhite, 'Cela doit être un chiffre', context, null);
}
},
),
),
Container(
height: 100,
child: NumberInputContainer(
label: "Nombre de colonnes :",
initialValue: puzzleDTO.cols!,
isSmall: true,
maxLength: 2,
onChanged: (value) {
try {
puzzleDTO.cols = int.parse(value);
setState(() {
widget.onChanged(puzzleDTO);
});
} catch (e) {
showNotification(Colors.orange, kWhite, 'Cela doit être un chiffre', context, null);
}
},
),
),
],)
],
),
);
}
}