import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/resource_input_container.dart'; import 'package:manager_api_new/api.dart'; import 'dart:convert'; class PDFConfig extends StatefulWidget { final String? color; final String? label; final String initialValue; final ValueChanged onChanged; const PDFConfig({ Key? key, this.color, this.label, required this.initialValue, required this.onChanged, }) : super(key: key); @override _PDFConfigState createState() => _PDFConfigState(); } class _PDFConfigState extends State { late PdfDTO pdfDTO; @override void initState() { PdfDTO test = PdfDTO.fromJson(json.decode(widget.initialValue))!; pdfDTO = test; super.initState(); } @override Widget build(BuildContext context) { return Center( child: ResourceInputContainer( label: "Fichier PDF :", inResourceTypes: [ResourceType.Pdf], initialValue: pdfDTO.resourceId == null ? '': pdfDTO.resourceId, onChanged: (ResourceDTO resourceDTO) { pdfDTO.resourceUrl = resourceDTO.url; pdfDTO.resourceId = resourceDTO.id; widget.onChanged(jsonEncode(pdfDTO).toString()); } ), ); } }