From 1c885e85e023c308cc9625edae06b2158b197fdf Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Sat, 1 May 2021 01:10:53 +0200 Subject: [PATCH] Add select section logic + small fixes --- lib/Components/multi_select_container.dart | 20 ++- .../Section/section_detail_screen.dart | 156 ++++++++++++++++++ .../configuration_detail_screen.dart | 93 ++++++----- .../Configurations/configurations_screen.dart | 7 +- .../new_configuration_popup.dart | 4 +- .../Configurations/new_section_popup.dart | 18 +- 6 files changed, 247 insertions(+), 51 deletions(-) create mode 100644 lib/Screens/Configurations/Section/section_detail_screen.dart diff --git a/lib/Components/multi_select_container.dart b/lib/Components/multi_select_container.dart index bf2bce0..3745434 100644 --- a/lib/Components/multi_select_container.dart +++ b/lib/Components/multi_select_container.dart @@ -6,6 +6,7 @@ class MultiSelectContainer extends StatelessWidget { final String label; final List values; final List initialValue; + final bool isMultiple; final ValueChanged> 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 values; final List selectedValues; final Function(List) onSelectionChanged; // +added + final bool isMultiple; MultiSelectChip( this.values, this.selectedValues, + this.isMultiple, {this.onSelectionChanged} // +added ); @override @@ -69,10 +74,17 @@ class _MultiSelectChipState extends State { 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 }); }, ), diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart new file mode 100644 index 0000000..ed2fb4e --- /dev/null +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -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 { + SectionDTO sectionDTO; + + @override + Widget build(BuildContext context) { + final appContext = Provider.of(context); + Size size = MediaQuery.of(context).size; + + return Container( + child: FutureBuilder( + future: getSection(widget.id, appContext.getContext().clientAPI), + builder: (context, AsyncSnapshot 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 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; +} diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index 76758d5..5da9b99 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -39,7 +39,6 @@ class _ConfigurationDetailScreenState extends State { future: getConfiguration(this.widget, appContext.getContext().clientAPI), builder: (context, AsyncSnapshot 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 { ), 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 { ), ), 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 { } 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 { } 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 { Future getConfiguration(ConfigurationDetailScreen widget, Client client) async { ConfigurationDTO configuration = await client.configurationApi.configurationGetDetail(widget.id); - print(configuration); - return configuration; } Future> getSections(ConfigurationDTO configurationDTO, Client client) async { List sections = await client.sectionApi.sectionGetFromConfiguration(configurationDTO.id); - print(sections); return sections; } } diff --git a/lib/Screens/Configurations/configurations_screen.dart b/lib/Screens/Configurations/configurations_screen.dart index 7178985..7286cb8 100644 --- a/lib/Screens/Configurations/configurations_screen.dart +++ b/lib/Screens/Configurations/configurations_screen.dart @@ -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 { 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( diff --git a/lib/Screens/Configurations/new_configuration_popup.dart b/lib/Screens/Configurations/new_configuration_popup.dart index 142e77b..c8c9bae 100644 --- a/lib/Screens/Configurations/new_configuration_popup.dart +++ b/lib/Screens/Configurations/new_configuration_popup.dart @@ -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(); } } \ No newline at end of file diff --git a/lib/Screens/Configurations/new_section_popup.dart b/lib/Screens/Configurations/new_section_popup.dart index 6b196a8..544e14b 100644 --- a/lib/Screens/Configurations/new_section_popup.dart +++ b/lib/Screens/Configurations/new_section_popup.dart @@ -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 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.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(); } } \ No newline at end of file