import 'dart:io'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/foundation.dart'; import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/resource_tab.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; dynamic showNewResource(AppContext appContext, BuildContext context) async { ResourceDTO resourceDetailDTO = new ResourceDTO(); Size size = MediaQuery.of(context).size; var fileName; List? filesToSend; List? filesToSendWeb; var result = await 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("Nouvelle ressource", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)), /*Column( children: [ StringInputContainer( label: "Nom :", initialValue: resourceDetailDTO.label, onChanged: (value) { resourceDetailDTO.label = value; }, ), if (fileName != null) new Text(fileName), ], ),*/ Padding( padding: const EdgeInsets.only(top: 10.0), child: Container( width: size.width *0.85, height: size.height *0.5, child: ResourceTab( resourceDTO: resourceDetailDTO, onFileUpload: (List files) { filesToSend = files; }, onFileUploadWeb: (List files) { filesToSendWeb = files; }, ) ), ), ], ), ), ), 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: 150, height: 70, child: RoundedButton( text: "Créer", icon: Icons.check, color: kPrimaryColor, textColor: kWhite, press: () { //if (resourceDetailDTO.label != null && resourceDetailDTO.label!.trim() != '') { if(kIsWeb) { if(resourceDetailDTO.url != null || filesToSendWeb != null) { // TODO clarify resourceDetailDTO.data != null Navigator.pop(context, [resourceDetailDTO, filesToSend, filesToSendWeb]); } else { showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context, null); } } else { if (resourceDetailDTO.url != null || filesToSendWeb!.length > 0 || filesToSend!.length > 0) { // TODO clarify resourceDetailDTO.data != null Navigator.pop(context, [resourceDetailDTO, filesToSend, filesToSendWeb]); } else { showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context, null); } } /*} else { showNotification(Colors.orange, kWhite, 'Veuillez donner un nom à la ressource', context, null); }*/ //Navigator.of(context).pop(); //create(resourceDetailDTO, fileToSend, appContext, context); }, fontSize: 20, ), ), ), ], ), ], ), context: context ); return result; }