From 7195ebb64ffe593a1e0d864da93579e9fd3f274b Mon Sep 17 00:00:00 2001 From: Fransolet Thomas Date: Wed, 22 Jun 2022 18:54:27 +0200 Subject: [PATCH] Add Article management ! --- .../SubSection/Article/article_config.dart | 208 ++++++++++++++++++ .../Section/section_detail_screen.dart | 38 +++- lib/Screens/login_screen.dart | 2 +- pubspec.lock | 14 ++ pubspec.yaml | 2 + 5 files changed, 254 insertions(+), 10 deletions(-) create mode 100644 lib/Screens/Configurations/Section/SubSection/Article/article_config.dart diff --git a/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart b/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart new file mode 100644 index 0000000..792dd41 --- /dev/null +++ b/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart @@ -0,0 +1,208 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:manager_app/Components/check_input_container.dart'; +import 'package:manager_app/Components/multi_string_input_container.dart'; +import 'package:manager_app/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart'; +import 'package:manager_app/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart'; +import 'package:manager_app/app_context.dart'; +import 'package:manager_app/constants.dart'; +import 'package:managerapi/api.dart'; +import 'dart:convert'; + +import 'package:provider/provider.dart'; + + +class ArticleConfig extends StatefulWidget { + final String color; + final String label; + final String initialValue; + final ValueChanged onChanged; + const ArticleConfig({ + Key key, + this.color, + this.label, + this.initialValue, + this.onChanged, + }) : super(key: key); + + @override + _ArticleConfigState createState() => _ArticleConfigState(); +} + +class _ArticleConfigState extends State { + ArticleDTO articleDTO; + + @override + void initState() { + super.initState(); + articleDTO = ArticleDTO.fromJson(json.decode(widget.initialValue)); + List test = new List.from(articleDTO.images); + + articleDTO.images = test; + articleDTO.images.sort((a, b) => a.order.compareTo(b.order)); + } + + @override + Widget build(BuildContext context) { + final appContext = Provider.of(context); + Size size = MediaQuery.of(context).size; + + void _onReorder(int oldIndex, int newIndex) { + setState( + () { + if (newIndex > oldIndex) { + newIndex -= 1; + } + final ImageDTO item = articleDTO.images.removeAt(oldIndex); + articleDTO.images.insert(newIndex, item); + + var i = 0; + articleDTO.images.forEach((image) { + image.order = i; + i++; + }); + + widget.onChanged(jsonEncode(articleDTO).toString()); + }, + ); + } + + return + SingleChildScrollView( + child: Column( + children: [ + Container( + height: size.height * 0.1, + //width: size.width * 0.5,//, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + // Bad + MultiStringContainer( + label: "Contenu affiché:", + modalLabel: "Contenu", + color: kPrimaryColor, + initialValue: articleDTO != null ? articleDTO.content : [], + onGetResult: (value) { + setState(() { + if (articleDTO.content != value) { + articleDTO.content = value; + //save(true, articleDTO, appContext); + widget.onChanged(jsonEncode(articleDTO).toString()); + } + }); + }, + maxLines: 1, + ), + CheckInputContainer( + label: "Contenu au-dessus :", + isChecked: articleDTO.isContentTop, + onChanged: (value) { + setState(() { + print(value); + articleDTO.isContentTop = value; + widget.onChanged(jsonEncode(articleDTO).toString()); + }); + }, + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(25), + border: Border.all(width: 1.5, color: kSecond) + ), + child: Stack( + children: [ + Padding( + padding: const EdgeInsets.only(top: 40, left: 10, right: 10, bottom: 10), + child: Container( + height: 250, + width: size.height * 0.95, + child: ReorderableListView( + onReorder: _onReorder, + scrollDirection: Axis.horizontal, + padding: const EdgeInsets.symmetric(vertical: 20.0), + children: List.generate( + articleDTO.images.length, + (index) { + return ListViewCardImage( + articleDTO.images, + index, + Key('$index'), + appContext, + (images) { + setState(() { + List test = new List.from(images); + articleDTO.images = test; + List testToSend = new List.from(images); + testToSend = testToSend.where((element) => element.source_ != null).toList(); + var articleToSend = new ArticleDTO(); + articleToSend.images = testToSend; + widget.onChanged(jsonEncode(articleToSend).toString()); + }); + } + ); + }, + ), + ), + ), + ), + Positioned( + top: 10, + left: 10, + child: Text( + "Images", + style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500), + ), + ), + Positioned( + bottom: 15, + right: 15, + child: InkWell( + onTap: () async { + var result = await showNewOrUpdateImageSlider(null, appContext, context); + if (result != null) + { + setState(() { + result.order = articleDTO.images.length; + articleDTO.images.add(result); + widget.onChanged(jsonEncode(articleDTO).toString()); + }); + } + }, + child: Container( + height: MediaQuery.of(context).size.width * 0.04, + width: MediaQuery.of(context).size.width * 0.04, + child: Icon( + Icons.add, + color: kTextLightColor, + size: 30.0, + ), + decoration: BoxDecoration( + color: kSuccess, + 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 + ), + ], + ), + ), + ), + ), + ]), + ), + ), + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index 6336147..a91550b 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -16,10 +16,12 @@ import 'package:managerapi/api.dart'; import 'package:provider/provider.dart'; import 'package:intl/intl.dart'; +import 'SubSection/Article/article_config.dart'; import 'SubSection/Map/map_config.dart'; import 'SubSection/Menu/menu_config.dart'; import 'SubSection/Quizz/quizz_config.dart'; import 'SubSection/Slider/slider_config.dart'; +import 'package:qr_flutter/qr_flutter.dart'; class SectionDetailScreen extends StatefulWidget { final String id; @@ -184,15 +186,22 @@ class _SectionDetailScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ - ImageInputContainer( - label: "Image :", - initialValue: sectionDTO != null ? sectionDTO.imageId : "", - color: kPrimaryColor, - onChanged: (ResourceDTO resource) { - sectionDTO.imageId = resource.id; - sectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; - }, - ) + if(sectionDTO.type != SectionType.article) + ImageInputContainer( + label: "Image :", + initialValue: sectionDTO != null ? sectionDTO.imageId : "", + color: kPrimaryColor, + onChanged: (ResourceDTO resource) { + sectionDTO.imageId = resource.id; + sectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + }, + ) + else + QrImage( + data: sectionDTO.id, + version: QrVersions.auto, + size: 200.0, + ), ], ) ], @@ -355,6 +364,17 @@ class _SectionDetailScreenState extends State { sectionDTO.data = data; }, ); + case SectionType.article: + print(sectionDTO.data); + return ArticleConfig( + initialValue: sectionDTO.data, + onChanged: (String data) { + print("Received info in parent - article"); + print(data); + sectionDTO.data = data; + save(false, sectionDTO, appContext); + }, + ); } } } diff --git a/lib/Screens/login_screen.dart b/lib/Screens/login_screen.dart index 3de2ea6..af58d0e 100644 --- a/lib/Screens/login_screen.dart +++ b/lib/Screens/login_screen.dart @@ -116,7 +116,7 @@ class _LoginScreenState extends State { @override void initState() { this.isRememberMe = widget.session.rememberMe; - this.host = "http://192.168.1.19:8089"; //widget.session.host; + this.host = "http://localhost:5000"; //widget.session.host; // MDLF "http://192.168.1.19:8089" this.email = "test@email.be"; //widget.session.email; this.password = "kljqsdkljqsd"; //widget.session.password; super.initState(); diff --git a/pubspec.lock b/pubspec.lock index bd2d23c..f583881 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -289,6 +289,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "5.0.0" + qr: + dependency: transitive + description: + name: qr + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + qr_flutter: + dependency: "direct main" + description: + name: qr_flutter + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" rxdart: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index addb874..42e2ba8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,6 +40,8 @@ dependencies: drag_and_drop_lists: ^0.3.2 #path_provider: ^2.0.2 encrypt: ^5.0.0 + qr_flutter: ^4.0.0 + pdf: ^3.8.1 #msix: ^2.1.3 #window_size: # git: