manager-app/lib/Components/pdf_file_input_container.dart
Thomas Fransolet 4818a1af52 Configuration (create, update, del) + Section (create, update, del)
more test to be sure for section but should be ok
2025-05-13 17:12:04 +02:00

147 lines
5.0 KiB
Dart

import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:manager_api_new/api.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Map/category_list.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/PDF/pdf_list.dart';
import 'package:manager_app/constants.dart';
class PDFFileInputContainer extends StatefulWidget {
final Color color;
final String label;
List<OrderedTranslationAndResourceDTO> initialValue;
final ValueChanged<List<OrderedTranslationAndResourceDTO>> onChanged;
PDFFileInputContainer({
Key? key,
this.color = kSecond,
required this.label,
required this.initialValue,
required this.onChanged,
}) : super(key: key);
@override
_PDFFileInputContainerState createState() => _PDFFileInputContainerState();
}
class _PDFFileInputContainerState extends State<PDFFileInputContainer> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
child: Row(
children: [
Align(
alignment: AlignmentDirectional.centerStart,
child: Text(widget.label, style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300))
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: size.width *0.15,
child: InkWell(
onTap: () {
List<OrderedTranslationAndResourceDTO> newValues = <OrderedTranslationAndResourceDTO>[];
List<OrderedTranslationAndResourceDTO> initials = widget.initialValue;
showCreateOrUpdatePdfFiles("Fichiers PDF", initials, newValues, (value) {
widget.onChanged(value);
widget.initialValue = value;
}, context);
},
child: Container(
decoration: BoxDecoration(
color: kPrimaryColor,
borderRadius: BorderRadius.circular(50),
),
child: Padding(
padding: const EdgeInsets.only(left: 5, right: 5, top: 15, bottom: 15),
child: Center(
child: AutoSizeText(
"Changer",
style: TextStyle(color: kWhite),
maxLines: 2,
)
),
)
),
),
),
),
],
),
);
}
}
showCreateOrUpdatePdfFiles(String modalLabel, List<OrderedTranslationAndResourceDTO> values, List<OrderedTranslationAndResourceDTO> newValues, Function onGetResult, BuildContext context) {
showDialog(
builder: (BuildContext context) {
Size size = MediaQuery.of(context).size;
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))
),
title: Center(child: Text(modalLabel)),
content: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(width: 0.75, color: kSecond)
),
height: size.height * 0.7,
width: size.width * 0.65,
child: PDFList(pdfs: values, onChanged: (result) {
newValues = result;
onGetResult(result);
}),
)
),
actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 180,
height: 70,
child: RoundedButton(
text: "Annuler",
icon: Icons.undo,
color: kSecond,
press: () {
onGetResult(values);
Navigator.of(context).pop();
},
fontSize: 20,
),
),
Container(
width: 180,
height: 70,
child: RoundedButton(
text: "Valider",
icon: Icons.check,
color: kPrimaryColor,
textColor: kWhite,
press: () {
/*Function deepEq = const DeepCollectionEquality().equals;
if (!deepEq(values, newValues)) {
onGetResult(newValues);
}*/
Navigator.of(context).pop();
},
fontSize: 20,
),
),
],
),
],
);
}, context: context
);
}