2025-11-27 15:47:21 +01:00

161 lines
5.7 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 GameConfig extends StatefulWidget {
final String? color;
final String? label;
final GameDTO initialValue;
final ValueChanged<GameDTO> onChanged;
const GameConfig({
Key? key,
this.color,
this.label,
required this.initialValue,
required this.onChanged,
}) : super(key: key);
@override
_GameConfigState createState() => _GameConfigState();
}
class _GameConfigState extends State<GameConfig> {
late GameDTO gameDTO;
@override
void initState() {
GameDTO test = widget.initialValue;
/*if(test.puzzleImage == null) {
test.puzzleImage = ResourceDTO();
}*/
gameDTO = test;
gameDTO.rows = gameDTO.rows == null ? 3 : gameDTO.rows;
gameDTO.cols = gameDTO.cols == null ? 3 : gameDTO.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: gameDTO.puzzleImageId == null ? '': gameDTO.puzzleImageId,
onChanged: (ResourceDTO resourceDTO) {
setState(() {
if(resourceDTO.id == null)
{
gameDTO.puzzleImageId = null;
gameDTO.puzzleImage = null;
} else {
gameDTO.puzzleImageId = resourceDTO.id;
gameDTO.puzzleImage = resourceDTO;
}
widget.onChanged(gameDTO);
});
}
),
Container(
height: 100,
child: MultiStringInputAndResourceContainer(
label: "Message départ :",
modalLabel: "Message départ",
fontSize: 20,
color: kPrimaryColor,
initialValue: gameDTO.messageDebut != null ? gameDTO.messageDebut! : [],
resourceTypes: [ResourceType.Image, ResourceType.ImageUrl, ResourceType.VideoUrl, ResourceType.Video, ResourceType.Audio],
onGetResult: (value) {
if (gameDTO.messageDebut != value) {
setState(() {
gameDTO.messageDebut = value;
widget.onChanged(gameDTO);
});
}
},
maxLines: 1,
isTitle: false
)
),
Container(
height: 100,
child: MultiStringInputAndResourceContainer(
label: "Message fin :",
modalLabel: "Message fin",
fontSize: 20,
color: kPrimaryColor,
initialValue: gameDTO.messageFin != null ? gameDTO.messageFin! : [],
resourceTypes: [ResourceType.Image, ResourceType.ImageUrl, ResourceType.VideoUrl, ResourceType.Video, ResourceType.Audio],
onGetResult: (value) {
if (gameDTO.messageFin != value) {
setState(() {
gameDTO.messageFin = value;
widget.onChanged(gameDTO);
});
}
},
maxLines: 1,
isTitle: false
)
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 100,
child: NumberInputContainer(
label: "Nombre de lignes :",
initialValue: gameDTO.rows!,
isSmall: true,
maxLength: 2,
onChanged: (value) {
try {
gameDTO.rows = int.parse(value);
setState(() {
widget.onChanged(gameDTO);
});
} catch (e) {
showNotification(Colors.orange, kWhite, 'Cela doit être un chiffre', context, null);
}
},
),
),
Container(
height: 100,
child: NumberInputContainer(
label: "Nombre de colonnes :",
initialValue: gameDTO.cols!,
isSmall: true,
maxLength: 2,
onChanged: (value) {
try {
gameDTO.cols = int.parse(value);
setState(() {
widget.onChanged(gameDTO);
});
} catch (e) {
showNotification(Colors.orange, kWhite, 'Cela doit être un chiffre', context, null);
}
},
),
),
],)
],
),
);
}
}