manager-app/lib/Components/multi_string_input_html_modal.dart

157 lines
6.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:manager_app/Components/message_notification.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/Components/translation_input_and_resource_container.dart';
import 'package:manager_app/Components/translation_input_container.dart';
import 'package:manager_app/constants.dart';
import 'package:manager_api_new/api.dart';
import 'package:collection/collection.dart';
showMultiStringInputHTML (String label, String modalLabel, bool isTitle, List<TranslationDTO> values, List<TranslationDTO> newValues, Function onGetResult, int maxLines, List<ResourceType>? resourceTypes, BuildContext context, bool isMandatory) {
showDialog(
useRootNavigator: false,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))
),
insetPadding: const EdgeInsets.symmetric(horizontal: 60, vertical: 24),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 800),
child: Padding(
padding: const EdgeInsets.fromLTRB(24, 20, 24, 16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Center(child: Text(modalLabel, style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500))),
const SizedBox(height: 16),
SingleChildScrollView(
child: TranslationInputContainer(isTitle: isTitle, values: values, newValues: newValues, onGetResult: onGetResult, maxLines: maxLines, resourceTypes: resourceTypes),
),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
width: 180,
height: 70,
child: RoundedButton(
text: "Annuler",
icon: Icons.undo,
color: kSecond,
press: () {
onGetResult(values);
Navigator.of(context).pop();
},
fontSize: 20,
),
),
SizedBox(
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)) {
if(isMandatory && newValues.any((label) => label.value == null || label.value!.trim() == "")) {
showNotification(kPrimaryColor, kWhite, "La traduction n'est pas complète", context, null);
} else {
onGetResult(newValues);
Navigator.of(context).pop();
}
} else {
Navigator.of(context).pop();
}
},
fontSize: 20,
),
),
],
),
],
),
),
),
);
}, context: context
);
}
showMultiStringInputAndResourceHTML (String label, String modalLabel, bool isTitle, List<TranslationAndResourceDTO> values, List<TranslationAndResourceDTO> newValues, Function onGetResult, int maxLines, List<ResourceType>? resourceTypes, BuildContext context) {
showDialog(
useRootNavigator: false,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))
),
insetPadding: const EdgeInsets.symmetric(horizontal: 60, vertical: 24),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 800),
child: Padding(
padding: const EdgeInsets.fromLTRB(24, 20, 24, 16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Center(child: Text(modalLabel, style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500))),
const SizedBox(height: 16),
SingleChildScrollView(
child: TranslationInputAndResourceContainer(isTitle: isTitle, values: values, newValues: newValues, onGetResult: onGetResult, maxLines: maxLines, resourceTypes: resourceTypes),
),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
width: 180,
height: 70,
child: RoundedButton(
text: "Annuler",
icon: Icons.undo,
color: kSecond,
press: () {
onGetResult(values);
Navigator.of(context).pop();
},
fontSize: 20,
),
),
SizedBox(
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)) {
if(newValues.any((label) => label.value == null || label.value!.trim() == "")) {
showNotification(kPrimaryColor, kWhite, "La traduction n'est pas complète", context, null);
} else {
onGetResult(newValues);
Navigator.of(context).pop();
}
} else {
Navigator.of(context).pop();
}
},
fontSize: 20,
),
),
],
),
],
),
),
),
);
}, context: context
);
}