Add select section logic + small fixes
This commit is contained in:
parent
6fb7dbdad7
commit
1c885e85e0
@ -6,6 +6,7 @@ class MultiSelectContainer extends StatelessWidget {
|
||||
final String label;
|
||||
final List<String> values;
|
||||
final List<String> initialValue;
|
||||
final bool isMultiple;
|
||||
final ValueChanged<List<dynamic>> onChanged;
|
||||
const MultiSelectContainer({
|
||||
Key key,
|
||||
@ -13,6 +14,7 @@ class MultiSelectContainer extends StatelessWidget {
|
||||
this.label,
|
||||
this.values,
|
||||
this.initialValue,
|
||||
this.isMultiple,
|
||||
this.onChanged,
|
||||
}) : super(key: key);
|
||||
|
||||
@ -33,6 +35,7 @@ class MultiSelectContainer extends StatelessWidget {
|
||||
child: MultiSelectChip(
|
||||
values,
|
||||
initialValue,
|
||||
isMultiple,
|
||||
onSelectionChanged: (selectedList) {
|
||||
onChanged(selectedList);
|
||||
},
|
||||
@ -49,9 +52,11 @@ class MultiSelectChip extends StatefulWidget {
|
||||
final List<String> values;
|
||||
final List<String> selectedValues;
|
||||
final Function(List<String>) onSelectionChanged; // +added
|
||||
final bool isMultiple;
|
||||
MultiSelectChip(
|
||||
this.values,
|
||||
this.selectedValues,
|
||||
this.isMultiple,
|
||||
{this.onSelectionChanged} // +added
|
||||
);
|
||||
@override
|
||||
@ -69,10 +74,17 @@ class _MultiSelectChipState extends State<MultiSelectChip> {
|
||||
selectedColor: kPrimaryColor,
|
||||
onSelected: (selected) {
|
||||
setState(() {
|
||||
widget.selectedValues.contains(item)
|
||||
? widget.selectedValues.remove(item)
|
||||
: widget.selectedValues.add(item);
|
||||
widget.onSelectionChanged(widget.selectedValues); // +added
|
||||
if (widget.isMultiple) {
|
||||
widget.selectedValues.contains(item)
|
||||
? widget.selectedValues.remove(item)
|
||||
: widget.selectedValues.add(item);
|
||||
widget.onSelectionChanged(widget.selectedValues);
|
||||
} else {
|
||||
widget.selectedValues.clear();
|
||||
widget.selectedValues.add(item);
|
||||
widget.onSelectionChanged(widget.selectedValues);
|
||||
}
|
||||
// +added
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
156
lib/Screens/Configurations/Section/section_detail_screen.dart
Normal file
156
lib/Screens/Configurations/Section/section_detail_screen.dart
Normal file
@ -0,0 +1,156 @@
|
||||
import 'package:flutter/material.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:provider/provider.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class SectionDetailScreen extends StatefulWidget {
|
||||
final String id;
|
||||
SectionDetailScreen({Key key, @required this.id}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SectionDetailScreenState createState() => _SectionDetailScreenState();
|
||||
}
|
||||
|
||||
class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
||||
SectionDTO sectionDTO;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appContext = Provider.of<AppContext>(context);
|
||||
Size size = MediaQuery.of(context).size;
|
||||
|
||||
return Container(
|
||||
child: FutureBuilder(
|
||||
future: getSection(widget.id, appContext.getContext().clientAPI),
|
||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
print("euh fuck ?");
|
||||
print(snapshot.data);
|
||||
return bodySection(snapshot.data, size, appContext, context);
|
||||
} else if (snapshot.connectionState == ConnectionState.none) {
|
||||
return Text("No data");
|
||||
} else {
|
||||
return Center(child: Container(height: size.height * 0.2, child: Text('LOADING TODO FRAISE')));
|
||||
}
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget bodySection(SectionDTO sectionDTO, Size size, AppContext appContext, BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Container(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Align(
|
||||
alignment: AlignmentDirectional.bottomStart,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(sectionDTO.label, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(5.0),
|
||||
child: Text(DateFormat('dd/MM/yyyy').format(sectionDTO.dateCreation), style: TextStyle(fontSize: 15, fontWeight: FontWeight.w200)),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
ManagerAppContext managerAppContext = appContext.getContext();
|
||||
managerAppContext.selectedConfiguration = null;
|
||||
appContext.setContext(managerAppContext);
|
||||
},
|
||||
child: Container(
|
||||
child: Icon(
|
||||
Icons.arrow_back,
|
||||
color: kPrimaryColor,
|
||||
size: 50.0,
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
), // TITLE
|
||||
Container(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Container(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
StringContainer(
|
||||
label: "Nom :",
|
||||
initialValue: sectionDTO.label,
|
||||
onChanged: (value) {
|
||||
sectionDTO.label = value;
|
||||
},
|
||||
),
|
||||
StringContainer(
|
||||
label: "Description :",
|
||||
initialValue: sectionDTO.description,
|
||||
onChanged: (value) {
|
||||
sectionDTO.description = value;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Test :",
|
||||
),
|
||||
Text(
|
||||
"Test :",
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),// FIELDS SECTION
|
||||
//getButtons(configurationDTO, appContext),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<SectionDTO> getSection(String sectionId, dynamic appContext) async {
|
||||
print("YOULOU TEST GET SECTION");
|
||||
print(sectionId);
|
||||
dynamic section = await appContext.getContext().clientAPI.sectionApi.sectionGetDetail(sectionId);
|
||||
print("received section");
|
||||
print(section);
|
||||
return section;
|
||||
}
|
||||
@ -39,7 +39,6 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
|
||||
future: getConfiguration(this.widget, appContext.getContext().clientAPI),
|
||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
print(this.widget);
|
||||
return bodyConfiguration(snapshot.data, size, appContext, context);
|
||||
} else if (snapshot.connectionState == ConnectionState.none) {
|
||||
return Text("No data");
|
||||
@ -146,7 +145,7 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
|
||||
),
|
||||
ColorPickerInputContainer(
|
||||
label: "Couleur secondaire :",
|
||||
color: appContext.getContext().selectedConfiguration.secondaryColor,
|
||||
color: configurationDTO.secondaryColor,
|
||||
onChanged: (value) {
|
||||
configurationDTO.secondaryColor = value;
|
||||
},
|
||||
@ -157,7 +156,7 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.rectangle,
|
||||
@ -209,19 +208,23 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
|
||||
} else {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.add,
|
||||
color: kTextLightColor,
|
||||
size: 40.0,
|
||||
),
|
||||
AutoSizeText(
|
||||
"Nouvelle section",
|
||||
maxLines: 2,
|
||||
style: new TextStyle(color: kWhite, fontWeight: FontWeight.w400),
|
||||
minFontSize: 0,
|
||||
maxFontSize: 40,
|
||||
textAlign: TextAlign.center,
|
||||
Container(
|
||||
height: size.height*0.05,
|
||||
child: AutoSizeText(
|
||||
"Nouvelle section",
|
||||
maxLines: 2,
|
||||
style: new TextStyle(color: kWhite, fontWeight: FontWeight.w400),
|
||||
minFontSize: 2,
|
||||
maxFontSize: 40,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
@ -282,35 +285,44 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
|
||||
}
|
||||
|
||||
Widget bodyGrid(ConfigurationDTO configurationDTO, data, Size size, AppContext appContext) {
|
||||
return GridView.builder(
|
||||
shrinkWrap: true,
|
||||
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 8),
|
||||
itemCount: data.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return
|
||||
InkWell(
|
||||
onTap: () {
|
||||
if (data[index].id == null) {
|
||||
showNewSection(configurationDTO, appContext, context);
|
||||
} else {
|
||||
setState(() {
|
||||
ManagerAppContext managerAppContext = appContext.getContext();
|
||||
managerAppContext.selectedSection = data[index];
|
||||
selectedSection = data[index];
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
decoration: boxDecoration(data[index]),
|
||||
padding: const EdgeInsets.all(15),
|
||||
margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: getElement(data[index], size)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
child: Container(
|
||||
height: size.height *0.40,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 8),
|
||||
itemCount: data.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return
|
||||
InkWell(
|
||||
onTap: () {
|
||||
if (data[index].id == null) {
|
||||
showNewSection(configurationDTO, appContext, context);
|
||||
} else {
|
||||
setState(() {
|
||||
ManagerAppContext managerAppContext = appContext.getContext();
|
||||
managerAppContext.selectedSection = data[index];
|
||||
selectedSection = data[index];
|
||||
appContext.setContext(managerAppContext);
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
decoration: boxDecoration(data[index]),
|
||||
padding: const EdgeInsets.all(15),
|
||||
margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: getElement(data[index], size)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -353,14 +365,11 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
|
||||
|
||||
Future<ConfigurationDTO> getConfiguration(ConfigurationDetailScreen widget, Client client) async {
|
||||
ConfigurationDTO configuration = await client.configurationApi.configurationGetDetail(widget.id);
|
||||
print(configuration);
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
Future<List<SectionDTO>> getSections(ConfigurationDTO configurationDTO, Client client) async {
|
||||
List<SectionDTO> sections = await client.sectionApi.sectionGetFromConfiguration(configurationDTO.id);
|
||||
print(sections);
|
||||
return sections;
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,8 @@ import 'package:managerapi/api.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'Section/section_detail_screen.dart';
|
||||
|
||||
class ConfigurationsScreen extends StatefulWidget {
|
||||
ConfigurationsScreen({Key key}) : super(key: key);
|
||||
|
||||
@ -26,8 +28,11 @@ class _ConfigurationsScreenState extends State<ConfigurationsScreen> {
|
||||
|
||||
ManagerAppContext managerAppContext = appContext.getContext();
|
||||
|
||||
if (managerAppContext.selectedSection != null) {
|
||||
return SectionDetailScreen(id: managerAppContext.selectedSection.id);
|
||||
}
|
||||
if (managerAppContext.selectedConfiguration != null) {
|
||||
return ConfigurationDetailScreen(id: selectedConfiguration.id);
|
||||
return ConfigurationDetailScreen(id: managerAppContext.selectedConfiguration.id);
|
||||
} else {
|
||||
return Container(
|
||||
child: Column(
|
||||
|
||||
@ -76,6 +76,8 @@ void showNewConfiguration(AppContext appContext, BuildContext context) {
|
||||
|
||||
void create(ConfigurationDTO configurationDTO, AppContext appContext, context) async {
|
||||
if (configurationDTO.label != null) {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
ConfigurationDTO newConfiguration = await appContext.getContext().clientAPI.configurationApi.configurationCreate(configurationDTO);
|
||||
ManagerAppContext managerAppContext = appContext.getContext();
|
||||
managerAppContext.selectedConfiguration = null;
|
||||
@ -83,7 +85,5 @@ void create(ConfigurationDTO configurationDTO, AppContext appContext, context) a
|
||||
|
||||
// popup a toast.
|
||||
toast('La configuration a été créée avec succès');
|
||||
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
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';
|
||||
@ -8,8 +9,11 @@ import 'package:managerapi/api.dart';
|
||||
import 'package:overlay_support/overlay_support.dart';
|
||||
|
||||
void showNewSection(ConfigurationDTO configurationDTO, AppContext appContext, BuildContext context) {
|
||||
List<String> types = ["Map", "Slider", "Video", "Web", "Menu"];
|
||||
|
||||
SectionDTO sectionDTO = new SectionDTO();
|
||||
sectionDTO.configurationId = configurationDTO.id;
|
||||
|
||||
showDialog(
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
content: SingleChildScrollView(
|
||||
@ -25,6 +29,16 @@ void showNewSection(ConfigurationDTO configurationDTO, AppContext appContext, Bu
|
||||
sectionDTO.label = value;
|
||||
},
|
||||
),
|
||||
MultiSelectContainer(
|
||||
label: "Type :",
|
||||
initialValue: ["Map"],
|
||||
isMultiple: false,
|
||||
values: types,
|
||||
onChanged: (value) {
|
||||
var tempOutput = new List<String>.from(value);
|
||||
sectionDTO.type = SectionType.fromJson(tempOutput[0]);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@ -77,6 +91,8 @@ void showNewSection(ConfigurationDTO configurationDTO, AppContext appContext, Bu
|
||||
|
||||
void create(SectionDTO sectionDTO, AppContext appContext, BuildContext context) async {
|
||||
if (sectionDTO.label != null) {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
SectionDTO newSection = await appContext.getContext().clientAPI.sectionApi.sectionCreate(sectionDTO);
|
||||
ManagerAppContext managerAppContext = appContext.getContext();
|
||||
if (managerAppContext.selectedConfiguration.sectionIds == null) {
|
||||
@ -87,7 +103,5 @@ void create(SectionDTO sectionDTO, AppContext appContext, BuildContext context)
|
||||
|
||||
// popup a toast.
|
||||
toast('La section a été créée avec succès');
|
||||
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user