From ab833808a4d48ff90c31ee94cb2fbd260fe7914f Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Tue, 25 May 2021 19:07:44 +0200 Subject: [PATCH] Layout menu (translation as horizontal list) + add filter in resource screen (name) --- lib/Components/image_input_container.dart | 2 +- lib/Components/text_form_input_container.dart | 4 +- .../SubSection/showEditSubSection.dart | 118 ++++---- .../Section/section_detail_screen.dart | 24 +- .../configuration_detail_screen.dart | 271 +++++++++--------- .../Configurations/configurations_screen.dart | 3 +- lib/Screens/Resources/resource_body_grid.dart | 189 ++++++++++++ lib/Screens/Resources/resources_screen.dart | 125 ++------ 8 files changed, 420 insertions(+), 316 deletions(-) create mode 100644 lib/Screens/Resources/resource_body_grid.dart diff --git a/lib/Components/image_input_container.dart b/lib/Components/image_input_container.dart index 32b65b0..e34b202 100644 --- a/lib/Components/image_input_container.dart +++ b/lib/Components/image_input_container.dart @@ -48,7 +48,7 @@ class _ImageInputContainerState extends State { Padding( padding: const EdgeInsets.all(10.0), child: Container( - width: size.width *0.10, + width: size.width *0.08, child: InkWell( onTap: () { showSelectResourceModal( diff --git a/lib/Components/text_form_input_container.dart b/lib/Components/text_form_input_container.dart index 0f2e718..fca37f0 100644 --- a/lib/Components/text_form_input_container.dart +++ b/lib/Components/text_form_input_container.dart @@ -7,6 +7,7 @@ class TextFormInputContainer extends StatelessWidget { final String label; final String initialValue; final bool isTitle; + final int maxLines; final ValueChanged onChanged; const TextFormInputContainer({ Key key, @@ -14,6 +15,7 @@ class TextFormInputContainer extends StatelessWidget { this.label, this.initialValue, this.isTitle, + this.maxLines = 5, this.onChanged }) : super(key: key); @@ -42,7 +44,7 @@ class TextFormInputContainer extends StatelessWidget { keyboardType: TextInputType.multiline, textInputAction: TextInputAction.newline, minLines: 1, - maxLines: 5, + maxLines: maxLines, initialValue: initialValue, onChanged: onChanged, maxLength: isTitle ? 50 : 2000, diff --git a/lib/Screens/Configurations/Section/SubSection/showEditSubSection.dart b/lib/Screens/Configurations/Section/SubSection/showEditSubSection.dart index 0236160..0a8c716 100644 --- a/lib/Screens/Configurations/Section/SubSection/showEditSubSection.dart +++ b/lib/Screens/Configurations/Section/SubSection/showEditSubSection.dart @@ -29,6 +29,7 @@ void showEditSubSection(SectionDTO subSectionDTO, Function getResult, AppContext children: [ Text("Modifier sous section", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)), Column( + mainAxisAlignment: MainAxisAlignment.center, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceAround, @@ -48,34 +49,14 @@ void showEditSubSection(SectionDTO subSectionDTO, Function getResult, AppContext subSectionDTO.imageId = resource.id; }, ), - /*Column( - children: [ - StringInputContainer( - label: "Latitude :", - initialValue: geoPointDTO.latitude, - onChanged: (value) { - geoPointDTO.latitude = value; - }, - ), - StringInputContainer( - label: "Longitude :", - initialValue: geoPointDTO.longitude, - onChanged: (value) { - geoPointDTO.longitude = value; - }, - ) - ], - )*/ ], ), Container( + height: size.height * 0.33, width: double.infinity, - color: Colors.lightBlue, - child: SingleChildScrollView( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: getTranslations(context, appContext, subSectionDTO), - ), + child: ListView( + scrollDirection: Axis.horizontal, + children: getTranslations(context, appContext, subSectionDTO), ), ), Container( @@ -190,51 +171,54 @@ getTranslations(BuildContext context, AppContext appContext, SectionDTO subSecti ManagerAppContext managerAppContext = appContext.getContext(); for(var language in managerAppContext.selectedConfiguration.languages) { translations.add( - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Container( - width: MediaQuery.of(context).size.width *0.05, - height: MediaQuery.of(context).size.height *0.2, - decoration: BoxDecoration( - border: Border( - right: BorderSide(width: 1.5, color: kSecond), + SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Container( + width: MediaQuery.of(context).size.width *0.05, + height: MediaQuery.of(context).size.height *0.2, + decoration: BoxDecoration( + border: Border( + right: BorderSide(width: 1.5, color: kSecond), + ), + ), + child: Center(child: AutoSizeText(language.toUpperCase())) + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: Container( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + TextFormInputContainer( + label: "Titre:", + color: kWhite, + isTitle: true, + maxLines: 1, + initialValue: subSectionDTO.title.where((element) => element.language == language).first.value, + onChanged: (value) { + subSectionDTO.title.where((element) => element.language == language).first.value = value; + }, + ), + TextFormInputContainer( + label: "Description:", + color: kWhite, + isTitle: false, + initialValue: subSectionDTO.description.where((element) => element.language == language).first.value, + onChanged: (value) { + subSectionDTO.description.where((element) => element.language == language).first.value = value; + }, + ), + ], ), ), - child: Center(child: AutoSizeText(language.toUpperCase())) - ), - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: Container( - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - TextFormInputContainer( - label: "Titre:", - color: kWhite, - isTitle: true, - initialValue: subSectionDTO.title.where((element) => element.language == language).first.value, - onChanged: (value) { - subSectionDTO.title.where((element) => element.language == language).first.value = value; - }, - ), - TextFormInputContainer( - label: "Description:", - color: kWhite, - isTitle: false, - initialValue: subSectionDTO.description.where((element) => element.language == language).first.value, - onChanged: (value) { - subSectionDTO.description.where((element) => element.language == language).first.value = value; - }, - ), - ], - ), - ), - ) - ], + ) + ], + ), ), ) ); diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index 322d1e3..9e9c509 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -36,19 +36,17 @@ class _SectionDetailScreenState extends State { final appContext = Provider.of(context); Size size = MediaQuery.of(context).size; - return SingleChildScrollView( - child: FutureBuilder( - future: getSection(widget.id, appContext.getContext().clientAPI), - builder: (context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - 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'))); - } + return FutureBuilder( + future: getSection(widget.id, appContext.getContext().clientAPI), + builder: (context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + 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'))); } - ), + } ); } @@ -189,7 +187,7 @@ class _SectionDetailScreenState extends State { ), ),// FIELDS SECTION Container( - height: size.height * 0.45, + height: size.height * 0.39, width: size.width * 0.8, child: Padding( padding: const EdgeInsets.all(10.0), diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index 80db355..5aa12fe 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -34,19 +34,17 @@ class _ConfigurationDetailScreenState extends State { Widget build(BuildContext context) { final appContext = Provider.of(context); Size size = MediaQuery.of(context).size; - return Container( - child: FutureBuilder( - future: getConfiguration(this.widget, appContext.getContext().clientAPI), - builder: (context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - return bodyConfiguration(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'))); - } + return FutureBuilder( + future: getConfiguration(this.widget, appContext.getContext().clientAPI), + builder: (context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + return bodyConfiguration(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'))); } - ), + } ); } @@ -55,137 +53,148 @@ class _ConfigurationDetailScreenState extends State { 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(configurationDTO.label, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)), - Padding( - padding: const EdgeInsets.all(5.0), - child: Text(DateFormat('dd/MM/yyyy').format(configurationDTO.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, - ) - ) - ), + //height: size.height *0.12, + child: SingleChildScrollView( + 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(configurationDTO.label, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)), + Padding( + padding: const EdgeInsets.all(5.0), + child: Text(DateFormat('dd/MM/yyyy').format(configurationDTO.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: [ - StringInputContainer( - label: "Nom :", - initialValue: configurationDTO.label, - onChanged: (value) { - configurationDTO.label = value; - }, - ), - MultiSelectContainer( - label: "Langues :", - initialValue: configurationDTO.languages != null ? configurationDTO.languages: [], - values: languages, - isMultiple: true, - onChanged: (value) { - var tempOutput = new List.from(value); - configurationDTO.languages = tempOutput; - print(configurationDTO.languages); - }, - ), - ], + //height: size.height *0.76, + child: SingleChildScrollView( + 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: [ + StringInputContainer( + label: "Nom :", + initialValue: configurationDTO.label, + onChanged: (value) { + configurationDTO.label = value; + }, + ), + MultiSelectContainer( + label: "Langues :", + initialValue: configurationDTO.languages != null ? configurationDTO.languages: [], + values: languages, + isMultiple: true, + onChanged: (value) { + var tempOutput = new List.from(value); + configurationDTO.languages = tempOutput; + print(configurationDTO.languages); + }, + ), + ], + ), + Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ColorPickerInputContainer( + label: "Couleur principal :", + color: configurationDTO.primaryColor, + onChanged: (value) { + configurationDTO.primaryColor = value; + }, + ), + ColorPickerInputContainer( + label: "Couleur secondaire :", + color: configurationDTO.secondaryColor, + onChanged: (value) { + configurationDTO.secondaryColor = value; + }, + ), + ], + ) + ], + ), + ), + Padding( + padding: const EdgeInsets.all(20.0), + child: Container( + decoration: BoxDecoration( + shape: BoxShape.rectangle, + borderRadius: BorderRadius.circular(25.0), + border: Border.all(width: 0.5, color: kSecond) ), - Column( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ColorPickerInputContainer( - label: "Couleur principal :", - color: configurationDTO.primaryColor, - onChanged: (value) { - configurationDTO.primaryColor = value; - }, - ), - ColorPickerInputContainer( - label: "Couleur secondaire :", - color: configurationDTO.secondaryColor, - onChanged: (value) { - configurationDTO.secondaryColor = value; - }, - ), - ], - ) - ], - ), - ), - Padding( - padding: const EdgeInsets.all(20.0), - child: Container( - decoration: BoxDecoration( - shape: BoxShape.rectangle, - borderRadius: BorderRadius.circular(25.0), - border: Border.all(width: 0.5, color: kSecond) - ), - child: FutureBuilder( - future: getSections(configurationDTO, appContext.getContext().clientAPI), - builder: (context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - var tempOutput = new List.from(snapshot.data).where((section) => !section.isSubSection).toList(); - tempOutput.add(SectionDTO(id: null)); - return bodyGrid(configurationDTO, tempOutput, size, appContext); - } 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'))); + child: FutureBuilder( + future: getSections(configurationDTO, appContext.getContext().clientAPI), + builder: (context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + var tempOutput = new List.from(snapshot.data).where((section) => !section.isSubSection).toList(); + tempOutput.add(SectionDTO(id: null)); + return bodyGrid(configurationDTO, tempOutput, size, appContext); + } 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'))); + } } - } + ), ), ), - ), - ], + ], + ), ), ), ), ),// FIELDS SECTION - getButtons(configurationDTO, appContext), + Container( + //height: size.height *0.09, + child: SingleChildScrollView( + child: getButtons(configurationDTO, appContext) + ) + ) ], ); } diff --git a/lib/Screens/Configurations/configurations_screen.dart b/lib/Screens/Configurations/configurations_screen.dart index 0857bb9..caf3b71 100644 --- a/lib/Screens/Configurations/configurations_screen.dart +++ b/lib/Screens/Configurations/configurations_screen.dart @@ -34,7 +34,8 @@ class _ConfigurationsScreenState extends State { if (managerAppContext.selectedConfiguration != null) { return ConfigurationDetailScreen(id: managerAppContext.selectedConfiguration.id); } else { - return Container( + return Align( + alignment: AlignmentDirectional.topCenter, child: FutureBuilder( future: getConfigurations(appContext), builder: (context, AsyncSnapshot snapshot) { diff --git a/lib/Screens/Resources/resource_body_grid.dart b/lib/Screens/Resources/resource_body_grid.dart new file mode 100644 index 0000000..21bd932 --- /dev/null +++ b/lib/Screens/Resources/resource_body_grid.dart @@ -0,0 +1,189 @@ +import 'package:auto_size_text/auto_size_text.dart'; +import 'package:flutter/material.dart'; +import 'package:manager_app/Components/fetch_resource_icon.dart'; +import 'package:manager_app/Components/string_input_container.dart'; +import 'package:manager_app/Screens/Resources/new_resource_popup.dart'; +import 'package:manager_app/Screens/Resources/show_resource_popup.dart'; +import 'package:manager_app/app_context.dart'; +import 'package:manager_app/constants.dart'; +import 'package:managerapi/api.dart'; +import 'package:provider/provider.dart'; + +class ResourceBodyGrid extends StatefulWidget { + final List resources; //return ResourceDTO + final Function onSelect; + const ResourceBodyGrid({ + Key key, + this.resources, + this.onSelect, + }) : super(key: key); + + @override + _ResourceBodyGridState createState() => _ResourceBodyGridState(); +} + +class _ResourceBodyGridState extends State { + String filter; + List resourcesToShow; + + @override + void initState() { + resourcesToShow = widget.resources; + super.initState(); + } + + @override + Widget build(BuildContext context) { + final appContext = Provider.of(context); + Size size = MediaQuery.of(context).size; + + return bodyGrid(resourcesToShow, size, appContext); + } + + Widget bodyGrid(data, Size size, AppContext appContext) { + return Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: StringInputContainer( + label: "Recherche:", + onChanged: (String value) { + setState(() { + resourcesToShow = value.isEmpty ? widget.resources: widget.resources.where((ResourceDTO resource) => resource.label.toUpperCase().contains(value.toUpperCase())).toList(); + }); + }, + ), + ), + InkWell( + onTap: () { + widget.onSelect(ResourceDTO(id: null)); + }, + child: Container( + height: size.height *0.08, + width: size.height *0.08, + decoration: BoxDecoration( + color: Colors.lightGreen, + shape: BoxShape.rectangle, + borderRadius: BorderRadius.circular(25.0), + boxShadow: [ + BoxShadow( + color: kSecond, + spreadRadius: 0.5, + blurRadius: 5, + offset: Offset(0, 1.5), // changes position of shadow + ), + ], + ), + child: + Padding( + padding: const EdgeInsets.all(10.0), + child: LayoutBuilder(builder: (context, constraint) { + return new Icon(Icons.add, size: constraint.biggest.height, color: kTextLightColor); + }), + ), + ), + ) + ], + ), + Container( + height: size.height *0.85, + child: SingleChildScrollView( + child: GridView.builder( + shrinkWrap: true, + gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6), + itemCount: data.length, + itemBuilder: (BuildContext context, int index) { + return + InkWell( + onTap: () { + widget.onSelect(resourcesToShow[index]); + }, + child: Container( + decoration: boxDecoration(data[index], appContext), + padding: const EdgeInsets.all(15), + margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), + child: Align( + alignment: Alignment.center, + child: getElement(data[index], size, appContext) + ), + ), + ); + } + ), + ), + ), + ], + ); + } + + getElement(ResourceDTO resource, Size size, AppContext appContext) { + if (resource.id != null) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + height: size.width *0.01, + ), + Align( + alignment: Alignment.center, + child: AutoSizeText( + resource.label == null ? "" : resource.label, + style: new TextStyle(fontSize: 20), + maxLines: 1, + ), + ), + Align( + alignment: Alignment.bottomRight, + child: Icon( + getResourceIcon(resource.type), + color: kPrimaryColor, + size: 25, + ), + ), + ], + ); + } else { + return Icon( + Icons.add, + color: kTextLightColor, + size: 80.0, + ); + } + } +} + +boxDecoration(dynamic resourceDetailDTO, appContext) { + return BoxDecoration( + color: resourceDetailDTO.id == null ? Colors.lightGreen : kBackgroundColor, + shape: BoxShape.rectangle, + borderRadius: BorderRadius.circular(30.0), + image: resourceDetailDTO.id != null && resourceDetailDTO.type != ResourceType.videoUrl ? new DecorationImage( + fit: BoxFit.cover, + colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.3), BlendMode.dstATop), + image: new NetworkImage( + resourceDetailDTO.type == ResourceType.image ? appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resourceDetailDTO.id : resourceDetailDTO.data, + ), + ) : null, + boxShadow: [ + BoxShadow( + color: kSecond, + spreadRadius: 0.5, + blurRadius: 5, + offset: Offset(0, 1.5), // changes position of shadow + ), + ], + ); +} + + +Future> getResources(Function onGetResult, bool isImage, dynamic appContext) async { + List resources = await appContext.getContext().clientAPI.resourceApi.resourceGet(); + if (onGetResult != null && isImage) { + resources = resources.where((element) => element.type == ResourceType.image || element.type == ResourceType.imageUrl).toList(); + } + return resources; +} diff --git a/lib/Screens/Resources/resources_screen.dart b/lib/Screens/Resources/resources_screen.dart index fcb8e54..3f863bd 100644 --- a/lib/Screens/Resources/resources_screen.dart +++ b/lib/Screens/Resources/resources_screen.dart @@ -1,7 +1,9 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/fetch_resource_icon.dart'; +import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/Screens/Resources/new_resource_popup.dart'; +import 'package:manager_app/Screens/Resources/resource_body_grid.dart'; import 'package:manager_app/Screens/Resources/show_resource_popup.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; @@ -22,6 +24,7 @@ class ResourcesScreen extends StatefulWidget { } class _ResourcesScreenState extends State { + String filter; @override Widget build(BuildContext context) { @@ -34,8 +37,26 @@ class _ResourcesScreenState extends State { builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { var tempOutput = new List.from(snapshot.data); - tempOutput.add(ResourceDTO(id: null)); - return bodyGrid(tempOutput, size, appContext); + // tempOutput.add(ResourceDTO(id: null)); + return ResourceBodyGrid(resources: tempOutput, onSelect: (value) { + print("result parent"); + print(value); + if (widget.onGetResult == null) { + // Main screen + if (value.id == null) { + showNewResource(appContext, context); + } else { + showResource(value, appContext, context, size); + } + } else { + if (value.id == null) { + showNewResource(appContext, context); + } else { + // Result for select modal + widget.onGetResult(value); + } + } + },);//bodyGrid(tempOutput, size, appContext); } else if (snapshot.connectionState == ConnectionState.none) { return Text("No data"); } else { @@ -45,108 +66,8 @@ class _ResourcesScreenState extends State { ), ); } - - Widget bodyGrid(data, Size size, AppContext appContext) { - return GridView.builder( - shrinkWrap: true, - gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6), - itemCount: data.length, - itemBuilder: (BuildContext context, int index) { - return - InkWell( - onTap: () { - if (widget.onGetResult == null) { - // Main screen - if (data[index].id == null) { - showNewResource(appContext, context); - } else { - showResource(data[index], appContext, context, size); - } - } else { - if (data[index].id == null) { - showNewResource(appContext, context); - } else { - // Result for select modal - widget.onGetResult(data[index]); - } - } - - }, - child: Container( - decoration: boxDecoration(data[index], appContext), - padding: const EdgeInsets.all(15), - margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), - child: Align( - alignment: Alignment.center, - child: getElement(data[index], size, appContext) - ), - ), - ); - } - ); - } - - getElement(ResourceDTO resource, Size size, AppContext appContext) { - if (resource.id != null) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SizedBox( - height: size.width *0.01, - ), - Align( - alignment: Alignment.center, - child: AutoSizeText( - resource.label == null ? "" : resource.label, - style: new TextStyle(fontSize: 20), - maxLines: 1, - ), - ), - Align( - alignment: Alignment.bottomRight, - child: Icon( - getResourceIcon(resource.type), - color: kPrimaryColor, - size: 25, - ), - ), - ], - ); - } else { - return Icon( - Icons.add, - color: kTextLightColor, - size: 80.0, - ); - } - } } -boxDecoration(dynamic resourceDetailDTO, appContext) { - return BoxDecoration( - color: resourceDetailDTO.id == null ? Colors.lightGreen : kBackgroundColor, - shape: BoxShape.rectangle, - borderRadius: BorderRadius.circular(30.0), - image: resourceDetailDTO.id != null && resourceDetailDTO.type != ResourceType.videoUrl ? new DecorationImage( - fit: BoxFit.cover, - colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.3), BlendMode.dstATop), - image: new NetworkImage( - resourceDetailDTO.type == ResourceType.image ? appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resourceDetailDTO.id : resourceDetailDTO.data, - ), - ) : null, - boxShadow: [ - BoxShadow( - color: kSecond, - spreadRadius: 0.5, - blurRadius: 5, - offset: Offset(0, 1.5), // changes position of shadow - ), - ], - ); -} - - Future> getResources(Function onGetResult, bool isImage, dynamic appContext) async { List resources = await appContext.getContext().clientAPI.resourceApi.resourceGet(); if (onGetResult != null && isImage) {