105 lines
3.4 KiB
Dart
105 lines
3.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/Components/multi_string_input_and_resource_container.dart';
|
|
import 'package:manager_app/Components/multi_string_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 String initialValue;
|
|
final ValueChanged<String> 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 = PuzzleDTO.fromJson(json.decode(widget.initialValue))!;
|
|
if(test.image == null) {
|
|
test.image = PuzzleDTOImage();
|
|
}
|
|
puzzleDTO = test;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
ResourceInputContainer(
|
|
label: "Image du puzzle :",
|
|
initialValue: puzzleDTO.image!.resourceId == null ? '': puzzleDTO.image!.resourceId,
|
|
onChanged: (ResourceDTO resourceDTO) {
|
|
setState(() {
|
|
puzzleDTO.image!.resourceId = resourceDTO.id;
|
|
puzzleDTO.image!.resourceType = resourceDTO.type;
|
|
puzzleDTO.image!.resourceUrl = resourceDTO.url;
|
|
print(puzzleDTO.image);
|
|
widget.onChanged(jsonEncode(puzzleDTO).toString());
|
|
});
|
|
}
|
|
),
|
|
Container(
|
|
height: 100,
|
|
child: MultiStringInputAndResourceContainer(
|
|
label: "Message départ :",
|
|
modalLabel: "Message départ",
|
|
fontSize: 20,
|
|
color: kPrimaryColor,
|
|
initialValue: puzzleDTO.messageDebut != null ? puzzleDTO.messageDebut! : [],
|
|
onGetResult: (value) {
|
|
print("Mess depart test");
|
|
print(value);
|
|
if (puzzleDTO.messageDebut != value) {
|
|
setState(() {
|
|
puzzleDTO.messageDebut = value;
|
|
widget.onChanged(jsonEncode(puzzleDTO).toString());
|
|
});
|
|
}
|
|
},
|
|
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! : [],
|
|
onGetResult: (value) {
|
|
if (puzzleDTO.messageFin != value) {
|
|
setState(() {
|
|
puzzleDTO.messageFin = value;
|
|
widget.onChanged(jsonEncode(puzzleDTO).toString());
|
|
});
|
|
}
|
|
},
|
|
maxLines: 1,
|
|
isTitle: false
|
|
)
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|