Service generation + add order, resourceId to imageDTO + SliderDTO finish !

This commit is contained in:
Thomas Fransolet 2021-05-21 20:00:31 +02:00
parent 45ce7a345e
commit 3ecf85d35e
11 changed files with 220 additions and 175 deletions

View File

@ -11,7 +11,7 @@ class ImageInputContainer extends StatefulWidget {
final Color color; final Color color;
final String label; final String label;
final String initialValue; final String initialValue;
final ValueChanged<String> onChanged; final ValueChanged<ResourceDTO> onChanged;
const ImageInputContainer({ const ImageInputContainer({
Key key, Key key,
this.color = kSecond, this.color = kSecond,
@ -50,16 +50,16 @@ class _ImageInputContainerState extends State<ImageInputContainer> {
child: InkWell( child: InkWell(
onTap: () { onTap: () {
showSelectResourceModal( showSelectResourceModal(
"Sélectionner une ressource", "Sélectionner une ressource",
(String resourceId) { (ResourceDTO resource) {
widget.onChanged(resourceId); widget.onChanged(resource);
setState(() { setState(() {
resourceIdToShow = resourceId; resourceIdToShow = resource.id;
}); });
}, },
1, 1,
true, true,
context context
); );
}, },
child: getElement(widget.initialValue, context), child: getElement(widget.initialValue, context),

View File

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/new_update_image_slider.dart'; import 'package:manager_app/Screens/Configurations/Section/SubSection/new_update_image_slider.dart';
@ -29,75 +27,90 @@ class ListViewCard extends StatefulWidget {
class _ListViewCard extends State<ListViewCard> { class _ListViewCard extends State<ListViewCard> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Card( return Card(
margin: EdgeInsets.all(4), margin: EdgeInsets.all(4),
color: Colors.white, child: Stack(
child: Container( children: [
width: 200, Container(
height: 200, width: 200,
child: InkWell( height: 250,
splashColor: kPrimaryColor, decoration: BoxDecoration(
onTap: () { color: kWhite,
print("Item ${widget.listItems[widget.index]} selected."); border: Border.all(width: 0.5, color: kSecond),
showNewOrUpdateImageSlider( ),
widget.listItems[widget.index], child: Padding(
(value) { padding: const EdgeInsets.only(right: 20.0),
print("get result bébé"); child: Column(
setState(() { children: [
//List<ImageDTO> test = new List<ImageDTO>.from(sliderDTO.images); AutoSizeText(
widget.listItems[widget.index].title == null ? "" : widget.listItems[widget.index].title[0].value,
widget.listItems.add(value); style: new TextStyle(fontSize: 20),
widget.onChanged(widget.listItems); maxLines: 1,
}); ),
}, Container(
widget.appContext, height: MediaQuery.of(context).size.height * 0.1,
context); decoration: boxDecoration(widget.listItems[widget.index], widget.appContext),
}, padding: const EdgeInsets.all(15),
child: Container( margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
decoration: boxDecoration(widget.listItems[widget.index], widget.appContext), ),
padding: const EdgeInsets.all(15), Padding(
margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), padding: const EdgeInsets.all(8.0),
child: Align( child: AutoSizeText(
alignment: Alignment.center, widget.listItems[widget.index].description == null ? "" : widget.listItems[widget.index].description[0].value,
child: getElement(widget.listItems[widget.index], size, widget.appContext) style: new TextStyle(fontSize: 20),
maxLines: 3,
),
),
],
),
), ),
), ),
), Positioned(
), right: 0,
); bottom: 0,
} child: Row(
} children: [
InkWell(
getElement(ImageDTO imageDTO, Size size, AppContext appContext) { onTap: () {
if (imageDTO.title != null) { showNewOrUpdateImageSlider(
return Column( widget.listItems[widget.index],
crossAxisAlignment: CrossAxisAlignment.start, (value) {
mainAxisAlignment: MainAxisAlignment.spaceBetween, setState(() {
children: [ widget.listItems[widget.index] = value;
SizedBox( widget.onChanged(widget.listItems);
height: size.width *0.01, });
), },
Align( widget.appContext,
alignment: Alignment.center, context);
child: AutoSizeText( },
imageDTO.title == null ? "" : imageDTO.title[0].value, child: Padding(
style: new TextStyle(fontSize: 20), padding: const EdgeInsets.all(8.0),
maxLines: 1, child: Icon(
Icons.edit,
color: kPrimaryColor,
size: 25.0,
),
)
),
InkWell(
onTap: () {
widget.listItems.removeAt(widget.index);
widget.onChanged(widget.listItems);
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
Icons.delete,
color: kPrimaryColor,
size: 25.0,
),
)
),
],
)
), ),
), ],
Align( ),
alignment: Alignment.bottomRight,
child: Text("TODO")
),
],
);
} else {
return Icon(
Icons.add,
color: kTextLightColor,
size: 80.0,
); );
} }
} }
@ -106,10 +119,10 @@ boxDecoration(ImageDTO imageDTO, appContext) {
return BoxDecoration( return BoxDecoration(
color: imageDTO.title == null ? Colors.lightGreen : kBackgroundColor, color: imageDTO.title == null ? Colors.lightGreen : kBackgroundColor,
shape: BoxShape.rectangle, shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(30.0), border: Border.all(width: 1.5, color: kSecond),
borderRadius: BorderRadius.circular(10.0),
image: imageDTO.title != null ? new DecorationImage( image: imageDTO.title != null ? new DecorationImage(
fit: BoxFit.cover, fit: BoxFit.scaleDown,
colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.3), BlendMode.dstATop),
image: new NetworkImage( image: new NetworkImage(
imageDTO.source_, imageDTO.source_,
), ),

View File

@ -10,12 +10,12 @@ import 'package:managerapi/api.dart';
void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppContext appContext, BuildContext context) { void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppContext appContext, BuildContext context) {
ImageDTO imageDTO = new ImageDTO(); ImageDTO imageDTO = new ImageDTO();
if (inputImageDTO.source_ != null) { if (inputImageDTO != null) {
print("inputImageDTO.source_ != null NOT NULLLLL"); print("inputImageDTO.source_ != null NOT NULLLLL");
imageDTO = inputImageDTO; imageDTO = inputImageDTO;
} else { } else {
imageDTO.title = new List<TranslationDTO>(); imageDTO.title = <TranslationDTO>[];
imageDTO.description = new List<TranslationDTO>(); imageDTO.description = <TranslationDTO>[];
ManagerAppContext managerAppContext = appContext.getContext(); ManagerAppContext managerAppContext = appContext.getContext();
managerAppContext.selectedConfiguration.languages.forEach((element) { managerAppContext.selectedConfiguration.languages.forEach((element) {
@ -25,7 +25,6 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC
imageDTO.title.add(translationDTO); imageDTO.title.add(translationDTO);
imageDTO.description.add(translationDTO); imageDTO.description.add(translationDTO);
}); });
} }
print(imageDTO); print(imageDTO);
@ -46,11 +45,11 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC
children: [ children: [
ImageInputContainer( ImageInputContainer(
label: "Image :", label: "Image :",
initialValue: imageDTO.source_, initialValue: imageDTO.resourceId,
color: kPrimaryColor, color: kPrimaryColor,
onChanged: (value) { onChanged: (ResourceDTO resource) {
print("received value in grant older"); imageDTO.source_ = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id;
imageDTO.source_ = value; imageDTO.resourceId = resource.id;
}, },
), ),
MultiStringContainer( MultiStringContainer(
@ -78,7 +77,6 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC
imageDTO.description = value; imageDTO.description = value;
} }
print(imageDTO.description); print(imageDTO.description);
}, },
maxLines: 1, maxLines: 1,
), ),
@ -111,10 +109,10 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC
Align( Align(
alignment: AlignmentDirectional.bottomEnd, alignment: AlignmentDirectional.bottomEnd,
child: Container( child: Container(
width: inputImageDTO.source_ != null ? 200: 150, width: inputImageDTO != null ? 220: 150,
height: 70, height: 70,
child: RoundedButton( child: RoundedButton(
text: inputImageDTO.source_ != null ? "Sauvegarder" : "Créer", text: inputImageDTO != null ? "Sauvegarder" : "Créer",
icon: Icons.check, icon: Icons.check,
color: kPrimaryColor, color: kPrimaryColor,
textColor: kWhite, textColor: kWhite,

View File

@ -35,17 +35,12 @@ class _SliderConfigState extends State<SliderConfig> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
sliderDTO = SliderDTO.fromJson(json.decode(widget.initialValue)); sliderDTO = SliderDTO.fromJson(json.decode(widget.initialValue));
List<ImageDTO> test = new List<ImageDTO>.from(sliderDTO.images); List<ImageDTO> test = new List<ImageDTO>.from(sliderDTO.images);
test.add(ImageDTO(title: null));
sliderDTO.images = test; sliderDTO.images = test;
print(sliderDTO); sliderDTO.images.sort((a, b) => a.order.compareTo(b.order));
} }
@override @override
@ -61,73 +56,94 @@ class _SliderConfigState extends State<SliderConfig> {
} }
final ImageDTO item = sliderDTO.images.removeAt(oldIndex); final ImageDTO item = sliderDTO.images.removeAt(oldIndex);
sliderDTO.images.insert(newIndex, item); sliderDTO.images.insert(newIndex, item);
var i = 0;
sliderDTO.images.forEach((image) {
image.order = i;
i++;
});
widget.onChanged(jsonEncode(sliderDTO).toString());
}, },
); );
} }
return ReorderableListView( return Stack(
onReorder: _onReorder, children: [
scrollDirection: Axis.horizontal, ReorderableListView(
padding: const EdgeInsets.symmetric(vertical: 25.0), onReorder: _onReorder,
children: List.generate( scrollDirection: Axis.horizontal,
sliderDTO.images.length, padding: const EdgeInsets.symmetric(vertical: 20.0),
(index) { children: List.generate(
return ListViewCard( sliderDTO.images.length,
sliderDTO.images, (index) {
index, return ListViewCard(
Key('$index'), sliderDTO.images,
appContext, index,
(images) { Key('$index'),
print(images); appContext,
print("ONCHANEGDE"); (images) {
setState(() {
setState(() { List<ImageDTO> test = new List<ImageDTO>.from(images);
List<ImageDTO> test = new List<ImageDTO>.from(images); sliderDTO.images = test;
sliderDTO.images = test; List<ImageDTO> testToSend = new List<ImageDTO>.from(images);
List<ImageDTO> testToSend = new List<ImageDTO>.from(images); testToSend = testToSend.where((element) => element.source_ != null).toList();
testToSend = testToSend.where((element) => element.source_ != null).toList(); var sliderToSend = new SliderDTO();
var sliderToSend = new SliderDTO(); sliderToSend.images = testToSend;
sliderToSend.images = testToSend; widget.onChanged(jsonEncode(sliderToSend).toString());
widget.onChanged(jsonEncode(sliderToSend).toString()); });
}); }
} );
); },
}, ),
), ),
); Positioned(
bottom: 0,
return GridView.builder( right: 0,
shrinkWrap: true, child: InkWell(
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 8), onTap: () {
itemCount: sliderDTO.images.length, showNewOrUpdateImageSlider(
itemBuilder: (BuildContext context, int index) { null,
return (ImageDTO image) {
InkWell( print("get result bébé showNewOrUpdateImageSlider");
onTap: () { if (this.mounted) {
// Main screen
showNewOrUpdateImageSlider(
sliderDTO.images[index],
(value) {
print("get result bébé");
setState(() { setState(() {
sliderDTO.images.add(value); image.order = sliderDTO.images.length;
sliderDTO.images.add(image);
widget.onChanged(jsonEncode(sliderDTO).toString()); widget.onChanged(jsonEncode(sliderDTO).toString());
}); });
}, } else {
appContext, print("DISPOSE MEEEEERDE");
context); }
}, },
child: Container( appContext,
decoration: boxDecoration(sliderDTO.images[index], appContext), context);
padding: const EdgeInsets.all(15), },
margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), child: Container(
child: Align( height: MediaQuery.of(context).size.width * 0.04,
alignment: Alignment.center, width: MediaQuery.of(context).size.width * 0.04,
child: getElement(sliderDTO.images[index], size, appContext) child: Icon(
), Icons.add,
color: kTextLightColor,
size: 30.0,
), ),
); decoration: BoxDecoration(
} color: Colors.lightGreen,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(20.0),
boxShadow: [
BoxShadow(
color: kSecond,
spreadRadius: 0.5,
blurRadius: 5,
offset: Offset(0, 1.5), // changes position of shadow
),
],
),
),
),
),
],
); );
} }
} }

View File

@ -147,9 +147,9 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
label: "Image :", label: "Image :",
initialValue: sectionDTO.imageId, initialValue: sectionDTO.imageId,
color: kPrimaryColor, color: kPrimaryColor,
onChanged: (value) { onChanged: (ResourceDTO resource) {
print("received value in grant older"); print("received value in grant older");
sectionDTO.imageId = value; sectionDTO.imageId = resource.id;
}, },
), ),
], ],

View File

@ -9,7 +9,7 @@ import 'package:managerapi/api.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class ResourcesScreen extends StatefulWidget { class ResourcesScreen extends StatefulWidget {
final Function onGetResult; final Function onGetResult; //return ResourceDTO
final bool isImage; final bool isImage;
const ResourcesScreen({ const ResourcesScreen({
Key key, Key key,
@ -71,7 +71,7 @@ class _ResourcesScreenState extends State<ResourcesScreen> {
showNewResource(appContext, context); showNewResource(appContext, context);
} else { } else {
// Result for select modal // Result for select modal
widget.onGetResult(data[index].id); widget.onGetResult(data[index]);
} }
} }

View File

@ -19,11 +19,11 @@ showSelectResourceModal (String text, Function onGetResult, int maxLines, bool o
children: [ children: [
Container( Container(
width: size.width * 0.6, width: size.width * 0.6,
height: size.height * 0.6, height: size.height * 0.75,
child: ResourcesScreen( child: ResourcesScreen(
onGetResult: (String resourceId) { onGetResult: (ResourceDTO resource) {
if (resourceId != null) { if (resource != null) {
onGetResult(resourceId); onGetResult(resource);
Navigator.of(mainContext).pop(); Navigator.of(mainContext).pop();
} }
}, },

View File

@ -68,11 +68,3 @@ lib/model/user_detail_dto.dart
lib/model/video_dto.dart lib/model/video_dto.dart
lib/model/web_dto.dart lib/model/web_dto.dart
pubspec.yaml pubspec.yaml
test/geo_point_dto_test.dart
test/image_dto_test.dart
test/map_dto_test.dart
test/map_type_test.dart
test/menu_dto_test.dart
test/slider_dto_test.dart
test/video_dto_test.dart
test/web_dto_test.dart

View File

@ -10,7 +10,9 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**title** | [**List<TranslationDTO>**](TranslationDTO.md) | | [optional] [default to const []] **title** | [**List<TranslationDTO>**](TranslationDTO.md) | | [optional] [default to const []]
**description** | [**List<TranslationDTO>**](TranslationDTO.md) | | [optional] [default to const []] **description** | [**List<TranslationDTO>**](TranslationDTO.md) | | [optional] [default to const []]
**resourceId** | **String** | | [optional]
**source_** | **String** | | [optional] **source_** | **String** | | [optional]
**order** | **int** | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -14,29 +14,39 @@ class ImageDTO {
ImageDTO({ ImageDTO({
this.title, this.title,
this.description, this.description,
this.resourceId,
this.source_, this.source_,
this.order,
}); });
List<TranslationDTO> title; List<TranslationDTO> title;
List<TranslationDTO> description; List<TranslationDTO> description;
String resourceId;
String source_; String source_;
int order;
@override @override
bool operator ==(Object other) => identical(this, other) || other is ImageDTO && bool operator ==(Object other) => identical(this, other) || other is ImageDTO &&
other.title == title && other.title == title &&
other.description == description && other.description == description &&
other.source_ == source_; other.resourceId == resourceId &&
other.source_ == source_ &&
other.order == order;
@override @override
int get hashCode => int get hashCode =>
(title == null ? 0 : title.hashCode) + (title == null ? 0 : title.hashCode) +
(description == null ? 0 : description.hashCode) + (description == null ? 0 : description.hashCode) +
(source_ == null ? 0 : source_.hashCode); (resourceId == null ? 0 : resourceId.hashCode) +
(source_ == null ? 0 : source_.hashCode) +
(order == null ? 0 : order.hashCode);
@override @override
String toString() => 'ImageDTO[title=$title, description=$description, source_=$source_]'; String toString() => 'ImageDTO[title=$title, description=$description, resourceId=$resourceId, source_=$source_, order=$order]';
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final json = <String, dynamic>{}; final json = <String, dynamic>{};
@ -46,9 +56,15 @@ class ImageDTO {
if (description != null) { if (description != null) {
json[r'description'] = description; json[r'description'] = description;
} }
if (resourceId != null) {
json[r'resourceId'] = resourceId;
}
if (source_ != null) { if (source_ != null) {
json[r'source'] = source_; json[r'source'] = source_;
} }
if (order != null) {
json[r'order'] = order;
}
return json; return json;
} }
@ -59,7 +75,9 @@ class ImageDTO {
: ImageDTO( : ImageDTO(
title: TranslationDTO.listFromJson(json[r'title']), title: TranslationDTO.listFromJson(json[r'title']),
description: TranslationDTO.listFromJson(json[r'description']), description: TranslationDTO.listFromJson(json[r'description']),
resourceId: json[r'resourceId'],
source_: json[r'source'], source_: json[r'source'],
order: json[r'order'],
); );
static List<ImageDTO> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) => static List<ImageDTO> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>

View File

@ -1450,9 +1450,15 @@ components:
nullable: true nullable: true
items: items:
$ref: '#/components/schemas/TranslationDTO' $ref: '#/components/schemas/TranslationDTO'
resourceId:
type: string
nullable: true
source: source:
type: string type: string
nullable: true nullable: true
order:
type: integer
format: int32
VideoDTO: VideoDTO:
type: object type: object
additionalProperties: false additionalProperties: false