import 'package:auto_size_text/auto_size_text.dart'; import 'package:manager_app/Components/image_input_container.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/text_form_input_container.dart'; import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppContext appContext, BuildContext context) { ImageDTO imageDTO = new ImageDTO(); if (inputImageDTO != null) { imageDTO = inputImageDTO; } else { imageDTO.title = []; imageDTO.description = []; ManagerAppContext managerAppContext = appContext.getContext(); managerAppContext.selectedConfiguration.languages.forEach((element) { var translationDTO = new TranslationDTO(); translationDTO.language = element; translationDTO.value = ""; imageDTO.title.add(translationDTO); imageDTO.description.add(translationDTO); }); } Size size = MediaQuery.of(context).size; showDialog( builder: (BuildContext context) => AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(20.0)) ), content: Container( width: size.width *0.5, child: SingleChildScrollView( child: Column( children: [ Text("Image/vidéo", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)), Column( children: [ ImageInputContainer( label: "Image :", initialValue: imageDTO.resourceId, color: kPrimaryColor, onChanged: (ResourceDTO resource) { imageDTO.source_ = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; imageDTO.resourceId = resource.id; }, ), Container( child: SingleChildScrollView( child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: getTranslations(context, appContext, imageDTO), ), ), ), ], ), ], ), ), ), actions: [ Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Align( alignment: AlignmentDirectional.bottomEnd, child: Container( width: 175, height: 70, child: RoundedButton( text: "Annuler", icon: Icons.undo, color: kSecond, press: () { Navigator.of(context).pop(); }, fontSize: 20, ), ), ), Align( alignment: AlignmentDirectional.bottomEnd, child: Container( width: inputImageDTO != null ? 220: 150, height: 70, child: RoundedButton( text: inputImageDTO != null ? "Sauvegarder" : "Créer", icon: Icons.check, color: kPrimaryColor, textColor: kWhite, press: () { getResult(imageDTO); Navigator.of(context).pop(); }, fontSize: 20, ), ), ), ], ), ], ), context: context ); } getTranslations(BuildContext context, AppContext appContext, ImageDTO imageDTO) { List translations = []; ManagerAppContext managerAppContext = appContext.getContext(); for(var language in managerAppContext.selectedConfiguration.languages) { translations.add( Padding( padding: const EdgeInsets.all(8.0), child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Container( width: MediaQuery.of(context).size.width *0.05, height: MediaQuery.of(context).size.height *0.2, decoration: BoxDecoration( border: Border( right: BorderSide(width: 1.5, color: kSecond), ), ), child: Center(child: AutoSizeText(language.toUpperCase())) ), Padding( padding: const EdgeInsets.only(left: 8.0), child: Container( child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.center, children: [ TextFormInputContainer( label: "Titre:", color: kWhite, isTitle: true, initialValue: imageDTO.title.where((element) => element.language == language).first.value, onChanged: (value) { imageDTO.title.where((element) => element.language == language).first.value = value; }, ), TextFormInputContainer( label: "Description:", color: kWhite, isTitle: false, initialValue: imageDTO.description.where((element) => element.language == language).first.value, onChanged: (value) { imageDTO.description.where((element) => element.language == language).first.value = value; }, ), ], ), ), ) ], ), ) ); } return translations; }