manager-app/lib/Screens/Configurations/new_section_popup.dart

106 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:manager_app/Components/multi_select_container.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/Components/string_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';
import 'package:overlay_support/overlay_support.dart';
void showNewSection(ConfigurationDTO configurationDTO, AppContext appContext, BuildContext context) {
SectionDTO sectionDTO = new SectionDTO();
sectionDTO.configurationId = configurationDTO.id;
showDialog(
builder: (BuildContext context) => AlertDialog(
content: SingleChildScrollView(
child: Column(
children: [
Text("Nouvelle section", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)),
Column(
children: [
StringContainer(
label: "Nom :",
initialValue: sectionDTO.label,
onChanged: (value) {
sectionDTO.label = value;
},
),
MultiSelectContainer(
label: "Type :",
initialValue: ["Map"],
isMultiple: false,
values: section_types,
onChanged: (value) {
var tempOutput = new List<String>.from(value);
sectionDTO.type = SectionType.fromJson(tempOutput[0]);
},
),
],
),
],
),
),
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: () {
//onYes();
create(sectionDTO, appContext, context);
},
fontSize: 20,
),
),
),
],
),
],
), context: context
);
}
void create(SectionDTO sectionDTO, AppContext appContext, BuildContext context) async {
if (sectionDTO.label != null) {
Navigator.of(context).pop();
print(sectionDTO);
SectionDTO newSection = await appContext.getContext().clientAPI.sectionApi.sectionCreate(sectionDTO);
ManagerAppContext managerAppContext = appContext.getContext();
if (managerAppContext.selectedConfiguration.sectionIds == null) {
managerAppContext.selectedConfiguration.sectionIds = new List<String>();
}
managerAppContext.selectedConfiguration.sectionIds.add(newSection.id);
appContext.setContext(managerAppContext);
// popup a toast.
toast('La section a été créée avec succès');
}
}