158 lines
5.9 KiB
Dart
158 lines
5.9 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:manager_api_new/api.dart';
|
|
|
|
void showNewConfiguration(AppContext appContext, ValueChanged<bool> isImport, BuildContext context, BuildContext mainContext) {
|
|
ConfigurationDTO configurationDTO = new ConfigurationDTO();
|
|
Size size = MediaQuery.of(mainContext).size;
|
|
configurationDTO.label = "";
|
|
|
|
showDialog(
|
|
builder: (BuildContext context) => AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(20.0))
|
|
),
|
|
content: SingleChildScrollView(
|
|
child: SizedBox(
|
|
width: size.width*0.35,
|
|
height: size.height*0.3,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Center(child: Text("Nouvelle configuration", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400))),
|
|
Center(
|
|
child: SizedBox(
|
|
height: 100,
|
|
child: 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() as ManagerAppContext).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: () {
|
|
if(configurationDTO.label != null && configurationDTO.label!.length > 2) {
|
|
create(configurationDTO, appContext, context);
|
|
} else {
|
|
showNotification(Colors.orange, kWhite, 'Veuillez spécifier un nom pour la nouvelle visite', context, null);
|
|
}
|
|
},
|
|
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) {
|
|
configurationDTO.dateCreation = DateTime.now();
|
|
configurationDTO.isMobile = false;
|
|
configurationDTO.isTablet = false;
|
|
configurationDTO.isOffline = false;
|
|
configurationDTO.instanceId = (appContext.getContext() as ManagerAppContext).instanceId;
|
|
await (appContext.getContext() as ManagerAppContext).clientAPI!.configurationApi!.configurationCreate(configurationDTO);
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
managerAppContext.selectedConfiguration = null;
|
|
appContext.setContext(managerAppContext);
|
|
|
|
showNotification(Colors.green, kWhite, 'La visite a été créée avec succès', context, null);
|
|
|
|
Navigator.of(context).pop();
|
|
}
|
|
} |