140 lines
4.8 KiB
Dart
140 lines
4.8 KiB
Dart
//import 'package:filepicker_windows/filepicker_windows.dart';
|
|
import 'package:file_picker/file_picker.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/string_input_container.dart';
|
|
import 'package:manager_app/Helpers/FileHelper.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 showNewConfiguration(AppContext appContext, ValueChanged<bool> isImport, BuildContext context, BuildContext mainContext) {
|
|
ConfigurationDTO configurationDTO = new ConfigurationDTO();
|
|
showDialog(
|
|
builder: (BuildContext context) => AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(20.0))
|
|
),
|
|
content: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
Text("Nouvelle configuration", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)),
|
|
Column(
|
|
children: [
|
|
StringInputContainer(
|
|
label: "Nom :",
|
|
initialValue: configurationDTO.label,
|
|
onChanged: (value) {
|
|
configurationDTO.label = value;
|
|
},
|
|
),
|
|
],
|
|
),
|
|
Text("ou"),
|
|
Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 5.0),
|
|
child: Text("Importer", style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)),
|
|
),
|
|
InkWell(
|
|
onTap: () async {
|
|
FilePickerResult result = await FilePicker.platform.pickFiles();
|
|
|
|
//String result = filePicker();
|
|
if (result != null) {
|
|
|
|
await FileHelper().importConfiguration(result, null, appContext.getContext().clientAPI, mainContext);
|
|
isImport(true);
|
|
Navigator.of(context).pop();
|
|
}
|
|
},
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: Icon(
|
|
Icons.file_upload,
|
|
color: kPrimaryColor,
|
|
size: 30
|
|
),
|
|
),
|
|
)
|
|
]
|
|
)
|
|
],
|
|
),
|
|
),
|
|
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: () {
|
|
create(configurationDTO, appContext, context);
|
|
},
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
), context: context
|
|
);
|
|
}
|
|
|
|
String filePicker() {
|
|
/*final file = OpenFilePicker()
|
|
..filterSpecification = {
|
|
'Fichier (*.json)': '*.json',
|
|
//'Video (*.mp4)': '*.mp4',
|
|
//'All Files': '*.*'
|
|
}
|
|
..defaultFilterIndex = 0
|
|
..title = 'Sélectionner un fichier';
|
|
|
|
final result = file.getFile();*/
|
|
var result;
|
|
|
|
return result != null ? result.path : null;
|
|
}
|
|
|
|
void create(ConfigurationDTO configurationDTO, AppContext appContext, context) async {
|
|
if (configurationDTO.label != null) {
|
|
|
|
await appContext.getContext().clientAPI.configurationApi.configurationCreate(configurationDTO);
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
managerAppContext.selectedConfiguration = null;
|
|
appContext.setContext(managerAppContext);
|
|
|
|
showNotification(Colors.green, kWhite, 'La configuration a été créée avec succès', context, null);
|
|
|
|
Navigator.of(context).pop();
|
|
}
|
|
} |