manager-app/lib/Components/multi_string_input_html_modal.dart
2023-12-27 18:11:25 +01:00

132 lines
5.1 KiB
Dart

import 'dart:ui';
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, bool isAudio, BuildContext context) {
showDialog(
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))
),
title: Center(child: Text(modalLabel)),
content: SingleChildScrollView(
child: TranslationInputContainer(isTitle: isTitle, values: values, newValues: newValues, onGetResult: onGetResult, maxLines: maxLines, isAudio: isAudio)
),
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)) {
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
);
}
showMultiStringInputAndResourceHTML (String label, String modalLabel, bool isTitle, List<TranslationAndResourceDTO> values, List<TranslationAndResourceDTO> newValues, Function onGetResult, int maxLines, bool isAudio, BuildContext context) {
showDialog(
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))
),
title: Center(child: Text(modalLabel)),
content: SingleChildScrollView(
child: TranslationInputAndResourceContainer(isTitle: isTitle, values: values, newValues: newValues, onGetResult: onGetResult, maxLines: maxLines, isAudio: isAudio)
),
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)) {
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
);
}