From e5a2d4f06a065be2ba6a2ad2d97deda2e841e108 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Thu, 20 Jun 2024 16:23:44 +0200 Subject: [PATCH] Update tarif to title (more char) + add image geopoint --- lib/Components/audio_input_container.dart | 5 +- lib/Components/resource_input_container.dart | 5 +- .../SubSection/Map/geopoint_image_list.dart | 5 +- .../Map/showNewOrUpdateGeoPoint.dart | 2 +- lib/Screens/Devices/devices_screen.dart | 94 ++++++++++--------- lib/Screens/Resources/resources_screen.dart | 61 ++++++++---- .../Resources/select_resource_modal.dart | 6 +- pubspec.yaml | 2 +- 8 files changed, 107 insertions(+), 73 deletions(-) diff --git a/lib/Components/audio_input_container.dart b/lib/Components/audio_input_container.dart index 809d4cb..7bb9376 100644 --- a/lib/Components/audio_input_container.dart +++ b/lib/Components/audio_input_container.dart @@ -71,7 +71,10 @@ class _AudioInputContainerState extends State { "Sélectionner une ressource", 1, [ResourceType.Audio], - context + context, + true, // IS SELECT + false, // IS ADD FALSE only for geopoint for now + true // IS REMOVE BUTTON ); if (result != null) { diff --git a/lib/Components/resource_input_container.dart b/lib/Components/resource_input_container.dart index bf92328..13e56e4 100644 --- a/lib/Components/resource_input_container.dart +++ b/lib/Components/resource_input_container.dart @@ -76,7 +76,10 @@ class _ResourceInputContainerState extends State { "Sélectionner une ressource", 1, widget.inResourceTypes, - context + context, + true, // IS SELECT + false, // IS ADD FALSE only for geopoint for now + true // IS REMOVE BUTTON ); if (result != null) { diff --git a/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart b/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart index 7513293..71c2b0d 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart @@ -92,7 +92,10 @@ class _GeoPointContentListState extends State { "Sélectionner une ressource", 1, [ResourceType.Image, ResourceType.ImageUrl, ResourceType.Video, ResourceType.VideoUrl, ResourceType.Audio], - context + context, + true, // IS SELECT TRUE + true, // IS ADD - only for geopoint for now + false // IS REMOVE BUTTON ); if (result != null) { setState(() { diff --git a/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart b/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart index 055811b..1d69bdb 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart @@ -207,7 +207,7 @@ void showNewOrUpdateGeoPoint(MapDTO mapDTO, GeoPointDTO? inputGeoPointDTO, Funct } }, maxLines: 1, - isTitle: true + isTitle: false ), ), Container( diff --git a/lib/Screens/Devices/devices_screen.dart b/lib/Screens/Devices/devices_screen.dart index 57a95df..c0a08ef 100644 --- a/lib/Screens/Devices/devices_screen.dart +++ b/lib/Screens/Devices/devices_screen.dart @@ -24,55 +24,57 @@ class _DevicesScreenState extends State { return Container( child: Align( alignment: AlignmentDirectional.topCenter, - child: Column( - children: [ - if(managerAppContext.pinCode != null) - Padding( - padding: const EdgeInsets.all(10.0), - child: Align( - alignment: AlignmentDirectional.centerStart, - child: AutoSizeText( - "Code pin: " + managerAppContext.pinCode.toString(), - style: TextStyle(fontSize: 25.0, fontWeight: FontWeight.w300), - maxLines: 2, - maxFontSize: 25.0, - textAlign: TextAlign.center, + child: SingleChildScrollView( + child: Column( + children: [ + if(managerAppContext.pinCode != null) + Padding( + padding: const EdgeInsets.all(10.0), + child: Align( + alignment: AlignmentDirectional.centerStart, + child: AutoSizeText( + "Code pin: " + managerAppContext.pinCode.toString(), + style: TextStyle(fontSize: 25.0, fontWeight: FontWeight.w300), + maxLines: 2, + maxFontSize: 25.0, + textAlign: TextAlign.center, + ), ), ), - ), - FutureBuilder( - future: getDevices(appContext), - builder: (context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - return GridView.builder( - shrinkWrap: true, - gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6), - itemCount: snapshot.data.length, - itemBuilder: (BuildContext context, int index) { - return Container( - decoration: boxDecoration(), - padding: const EdgeInsets.all(15), - margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), - child: Align( - alignment: Alignment.center, - child: DeviceElement(deviceDTO: snapshot.data[index]), //getElement() - ), - ); - } - ); - } else if (snapshot.connectionState == ConnectionState.none) { - return Text("No data"); - } else { - return Center( - child: Container( - height: size.height * 0.2, - child: LoadingCommon() - ) - ); + FutureBuilder( + future: getDevices(appContext), + builder: (context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + return GridView.builder( + shrinkWrap: true, + gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6), + itemCount: snapshot.data.length, + itemBuilder: (BuildContext context, int index) { + return Container( + decoration: boxDecoration(), + padding: const EdgeInsets.all(15), + margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), + child: Align( + alignment: Alignment.center, + child: DeviceElement(deviceDTO: snapshot.data[index]), //getElement() + ), + ); + } + ); + } else if (snapshot.connectionState == ConnectionState.none) { + return Text("No data"); + } else { + return Center( + child: Container( + height: size.height * 0.2, + child: LoadingCommon() + ) + ); + } } - } - ), - ], + ), + ], + ), ), ), ); diff --git a/lib/Screens/Resources/resources_screen.dart b/lib/Screens/Resources/resources_screen.dart index 4750158..a0315b8 100644 --- a/lib/Screens/Resources/resources_screen.dart +++ b/lib/Screens/Resources/resources_screen.dart @@ -19,6 +19,8 @@ class ResourcesScreen extends StatefulWidget { final Function? onGetResult; //return ResourceDTO final bool isImage; final bool isAddButton; + final bool isSelect; + final bool isRemoveButton; final bool isFilter; final List resourceTypes; const ResourcesScreen({ @@ -26,6 +28,8 @@ class ResourcesScreen extends StatefulWidget { this.isImage = false, this.onGetResult, this.isAddButton = true, + this.isRemoveButton = false, + this.isSelect = false, required this.resourceTypes, this.isFilter = true }) : super(key: key); @@ -49,7 +53,7 @@ class _ResourcesScreenState extends State { if (snapshot.connectionState == ConnectionState.done) { if(snapshot.data != null) { List tempOutput = []; - if(!widget.isAddButton) { + if(widget.isRemoveButton) { tempOutput.add(ResourceDTO()); tempOutput.addAll(new List.from(snapshot.data)); } else { @@ -61,9 +65,8 @@ class _ResourcesScreenState extends State { resourceTypesIn: widget.isImage ? resource_types.where((rt) => rt.type == ResourceType.Image || rt.type == ResourceType.ImageUrl).map((rt) => rt.type).toList() : widget.resourceTypes, isAddButton: widget.isAddButton, onSelect: (value) async { - if (widget.onGetResult == null) { - // Main screen - if (value.id == null) { + if(widget.isSelect) { + if (value.id == null && widget.isAddButton) { List? result = await showNewResource(appContext, context); if (result != null) { @@ -74,24 +77,42 @@ class _ResourcesScreenState extends State { // For refresh } } else { - var result = await showResource(value, appContext, context, size); - if(result != null) { - // Update resource - ManagerAppContext managerAppContext = appContext.getContext() as ManagerAppContext; - try{ - var resourceUpdated = managerAppContext.clientAPI!.resourceApi!.resourceUpdate(result); - setState(() { - // refresh ui - showNotification(kSuccess, kWhite, 'La ressource a été mise à jour avec succès', context, null); - }); - } catch (e) { - print("Error during updating resource"); - } - } + // Result for select modal + widget.onGetResult!(value); } } else { - // Result for select modal - widget.onGetResult!(value); + if (widget.onGetResult == null) { + // Main screen + if (value.id == null) { + List? result = await showNewResource(appContext, context); + if (result != null) + { + await create(result[0], result[1], result[2], appContext, context); + Future.delayed(Duration(seconds: 2), () { + setState(() {}); + }); + // For refresh + } + } else { + var result = await showResource(value, appContext, context, size); + if(result != null) { + // Update resource + ManagerAppContext managerAppContext = appContext.getContext() as ManagerAppContext; + try{ + var resourceUpdated = managerAppContext.clientAPI!.resourceApi!.resourceUpdate(result); + setState(() { + // refresh ui + showNotification(kSuccess, kWhite, 'La ressource a été mise à jour avec succès', context, null); + }); + } catch (e) { + print("Error during updating resource"); + } + } + } + } else { + // Result for select modal + widget.onGetResult!(value); + } } });//bodyGrid(tempOutput, size, appContext); } else { diff --git a/lib/Screens/Resources/select_resource_modal.dart b/lib/Screens/Resources/select_resource_modal.dart index afd2d30..7a0f5b0 100644 --- a/lib/Screens/Resources/select_resource_modal.dart +++ b/lib/Screens/Resources/select_resource_modal.dart @@ -5,7 +5,7 @@ import 'package:manager_app/Screens/Resources/resources_screen.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; -dynamic showSelectResourceModal (String text, int maxLines, List resourceTypes, BuildContext mainContext) async { /*Function onSelect,*/ +dynamic showSelectResourceModal (String text, int maxLines, List resourceTypes, BuildContext mainContext, bool isSelect, bool isAddButton, bool isRemoveButton) async { /*Function onSelect,*/ Size size = MediaQuery.of(mainContext).size; var result = await showDialog( @@ -21,7 +21,9 @@ dynamic showSelectResourceModal (String text, int maxLines, List r width: size.width * 0.85, height: size.height * 0.85, child: ResourcesScreen( - isAddButton: false, + isAddButton: isAddButton, + isSelect: isSelect, + isRemoveButton: isRemoveButton, onGetResult: (ResourceDTO? resource) { if (resource != null) { var result = resource; diff --git a/pubspec.yaml b/pubspec.yaml index 914ed88..873b7fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 2.0.3+7 +version: 2.0.4+8 environment: sdk: ">=3.1.0 <4.0.0"