124 lines
4.7 KiB
Dart
124 lines
4.7 KiB
Dart
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<File>? filesToSend;
|
|
List<PlatformFile>? 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),
|
|
],
|
|
),
|
|
Container(
|
|
width: size.width *0.5,
|
|
height: size.height *0.5,
|
|
child: ResourceTab(
|
|
resourceDTO: resourceDetailDTO,
|
|
onFileUpload: (List<File> files) {
|
|
filesToSend = files;
|
|
},
|
|
onFileUploadWeb: (List<PlatformFile> files) {
|
|
filesToSendWeb = files;
|
|
},
|
|
)
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
actions: <Widget>[
|
|
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.data != null || filesToSendWeb != null) {
|
|
Navigator.pop(context, [resourceDetailDTO, filesToSend, filesToSendWeb]);
|
|
} else {
|
|
showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context, null);
|
|
}
|
|
} else {
|
|
if (resourceDetailDTO.data != null || filesToSendWeb!.length > 0 || filesToSend!.length > 0) {
|
|
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;
|
|
}
|