50 lines
1.3 KiB
Dart

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<String> 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<PDFConfig> {
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());
}
),
);
}
}