From 869c071de5d91469f250910ab62469ac74c863ea Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Thu, 6 May 2021 23:05:29 +0200 Subject: [PATCH] Add border radius to alert dialog + test file picker on windows + new and show ressource (WIP) + ressource screen (wip) --- lib/Components/color_picker.dart | 5 +- lib/Components/confirmation_dialog.dart | 3 + lib/Components/multi_input_modal.dart | 3 + .../new_configuration_popup.dart | 4 +- .../Configurations/new_section_popup.dart | 3 + .../Resources/new_ressource_popup.dart | 124 ++++++++++++++++++ lib/Screens/Resources/resources_screen.dart | 98 ++++++++++++-- .../Resources/show_ressource_popup.dart | 81 ++++++++++++ pubspec.lock | 56 +++++++- pubspec.yaml | 1 + 10 files changed, 363 insertions(+), 15 deletions(-) create mode 100644 lib/Screens/Resources/new_ressource_popup.dart create mode 100644 lib/Screens/Resources/show_ressource_popup.dart diff --git a/lib/Components/color_picker.dart b/lib/Components/color_picker.dart index 873105d..8263667 100644 --- a/lib/Components/color_picker.dart +++ b/lib/Components/color_picker.dart @@ -11,7 +11,10 @@ showColorPicker (Color currentColor, Function onSelect, BuildContext context) { } showDialog( - builder: (BuildContext context) => AlertDialog( + builder: (BuildContext context) => AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(20.0)) + ), content: SingleChildScrollView( child: ColorPicker( pickerColor: currentColor, diff --git a/lib/Components/confirmation_dialog.dart b/lib/Components/confirmation_dialog.dart index 25dfab5..f7cd0e6 100644 --- a/lib/Components/confirmation_dialog.dart +++ b/lib/Components/confirmation_dialog.dart @@ -6,6 +6,9 @@ import 'package:manager_app/constants.dart'; showConfirmationDialog (String question, Function onNo, Function onYes, BuildContext context) { showDialog( builder: (BuildContext context) => AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(20.0)) + ), content: SingleChildScrollView( child: Text( question, diff --git a/lib/Components/multi_input_modal.dart b/lib/Components/multi_input_modal.dart index 9e3a28d..71e9abe 100644 --- a/lib/Components/multi_input_modal.dart +++ b/lib/Components/multi_input_modal.dart @@ -9,6 +9,9 @@ import 'package:collection/collection.dart'; showMultiStringInput (String text, List values, List newValues, Function onGetResult, int maxLines, BuildContext context) { /*Function onSelect,*/ showDialog( builder: (BuildContext context) => AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(20.0)) + ), title: Text(text), content: SingleChildScrollView( child: Column( diff --git a/lib/Screens/Configurations/new_configuration_popup.dart b/lib/Screens/Configurations/new_configuration_popup.dart index 6ec4b4e..c31435a 100644 --- a/lib/Screens/Configurations/new_configuration_popup.dart +++ b/lib/Screens/Configurations/new_configuration_popup.dart @@ -11,6 +11,9 @@ void showNewConfiguration(AppContext appContext, BuildContext context) { ConfigurationDTO configurationDTO = new ConfigurationDTO(); showDialog( builder: (BuildContext context) => AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(20.0)) + ), content: SingleChildScrollView( child: Column( children: [ @@ -60,7 +63,6 @@ void showNewConfiguration(AppContext appContext, BuildContext context) { color: kPrimaryColor, textColor: kWhite, press: () { - //onYes(); create(configurationDTO, appContext, context); }, fontSize: 20, diff --git a/lib/Screens/Configurations/new_section_popup.dart b/lib/Screens/Configurations/new_section_popup.dart index f748459..120f3f0 100644 --- a/lib/Screens/Configurations/new_section_popup.dart +++ b/lib/Screens/Configurations/new_section_popup.dart @@ -14,6 +14,9 @@ void showNewSection(ConfigurationDTO configurationDTO, AppContext appContext, Bu showDialog( builder: (BuildContext context) => AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(20.0)) + ), content: SingleChildScrollView( child: Column( children: [ diff --git a/lib/Screens/Resources/new_ressource_popup.dart b/lib/Screens/Resources/new_ressource_popup.dart new file mode 100644 index 0000000..f488d2d --- /dev/null +++ b/lib/Screens/Resources/new_ressource_popup.dart @@ -0,0 +1,124 @@ +import 'package:file_picker/file_picker.dart'; +import 'package:filepicker_windows/filepicker_windows.dart'; +import 'package:flutter/material.dart'; +import 'package:manager_app/Components/message_notification.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'; +import 'package:manager_app/app_context.dart'; +import 'package:manager_app/constants.dart'; +import 'package:managerapi/api.dart'; + +void showNewRessource(AppContext appContext, BuildContext context) { + RessourceDetailDTO ressourceDetailDTO = new RessourceDetailDTO(); + dynamic url = null; + showDialog( + builder: (BuildContext context) => AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(20.0)) + ), + content: SingleChildScrollView( + child: Column( + children: [ + Text("Nouvelle ressource", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)), + Column( + children: [ + StringContainer( + label: "Nom :", + initialValue: ressourceDetailDTO.label, + onChanged: (value) { + ressourceDetailDTO.label = value; + }, + ), + if (url != null) Image.network(url) + ], + ), + InkWell( + onTap: () async { + print("onTap upload"); + final file = OpenFilePicker() + ..filterSpecification = { + 'Images (*.jpg; *.png)': '*.jpg;*.png', + 'Video (*.mp4)': '*.mp4', + 'All Files': '*.*' + } + ..defaultFilterIndex = 0 + ..title = 'Sélectionner un fichier'; + + final result = file.getFile(); + if (result != null) { + print(result.path); + print(result.uri); + + // Read the file. + dynamic contents = await result.readAsBytes(); + print(contents); + + url = result.path; + + } + }, + child: Text("UPLOAD !"), + ), + ], + ), + ), + actions: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Align( + alignment: AlignmentDirectional.bottomEnd, + child: Container( + width: 175, + height: 70, + child: RoundedButton( + text: "Annuler", + icon: Icons.undo, + color: kSecond, + press: () { + Navigator.of(context).pop(); + }, + fontSize: 20, + ), + ), + ), + Align( + alignment: AlignmentDirectional.bottomEnd, + child: Container( + width: 150, + height: 70, + child: RoundedButton( + text: "Créer", + icon: Icons.check, + color: kPrimaryColor, + textColor: kWhite, + press: () { + create(ressourceDetailDTO, appContext, context); + }, + fontSize: 20, + ), + ), + ), + ], + ), + ], + ), context: context + ); +} + +void create(RessourceDetailDTO ressourceDetailDTO, AppContext appContext, context) async { + if (ressourceDetailDTO.label != null) { + Navigator.of(context).pop(); + + RessourceDetailDTO newRessource = await appContext.getContext().clientAPI.ressourceApi.ressourceCreate(ressourceDetailDTO); + print("newRessource"); + print(newRessource); + + // To refresh only (UGLY COOOOODE) + ManagerAppContext managerAppContext = appContext.getContext(); + appContext.setContext(managerAppContext); + + showNotification(Colors.green, kWhite, 'La ressource a été créée avec succès', context); + } +} \ No newline at end of file diff --git a/lib/Screens/Resources/resources_screen.dart b/lib/Screens/Resources/resources_screen.dart index 29d5b1e..beb8698 100644 --- a/lib/Screens/Resources/resources_screen.dart +++ b/lib/Screens/Resources/resources_screen.dart @@ -1,5 +1,10 @@ +import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; +import 'package:manager_app/Models/managerContext.dart'; +import 'package:manager_app/Screens/Resources/new_ressource_popup.dart'; +import 'package:manager_app/Screens/Resources/show_ressource_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'; @@ -20,22 +25,13 @@ class _ResourcesScreenState extends State { return Container( child: Column( children: [ - Text( - "Resources" - ), FutureBuilder( future: getResources(appContext), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { - return GridView.builder( - shrinkWrap: true, - gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4), - itemCount: snapshot.data.length, - itemBuilder: (BuildContext context, int index) { - return // User Picture - Text("Test resources"); - } - ); + var tempOutput = new List.from(snapshot.data); + tempOutput.add(RessourceDTO(id: null)); + return bodyGrid(tempOutput, size, appContext); } else if (snapshot.connectionState == ConnectionState.none) { return Text("No data"); } else { @@ -47,6 +43,84 @@ class _ResourcesScreenState extends State { ), ); } + + Widget bodyGrid(data, Size size, AppContext appContext) { + return GridView.builder( + shrinkWrap: true, + gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 8), + itemCount: data.length, + itemBuilder: (BuildContext context, int index) { + return // User Picture + InkWell( + onTap: () { + if (data[index].id == null) { + showNewRessource(appContext, context); + } else { + showRessource(data[index], appContext, context); + } + }, + 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) + ), + ), + ); + } + ); + } + + getElement(RessourceDTO ressource, Size size) { + if (ressource.id != null) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Align( + alignment: Alignment.centerLeft, + child: AutoSizeText( + ressource.label, + style: new TextStyle(fontSize: 25), + maxLines: 1, + ), + ), + Align( + alignment: Alignment.bottomRight, + child: AutoSizeText( + ressource.type.toString(), + style: new TextStyle(fontSize: 18, fontFamily: ""), + maxLines: 1, + ), + ), + ], + ); + } else { + return Icon( + Icons.add, + color: kTextLightColor, + size: 80.0, + ); + } + } +} + +boxDecoration(RessourceDTO ressourceDTO) { + return BoxDecoration( + color: ressourceDTO.id == null ? Colors.lightGreen : kTextLightColor, + 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 + ), + ], + ); } Future> getResources(dynamic appContext) async { diff --git a/lib/Screens/Resources/show_ressource_popup.dart b/lib/Screens/Resources/show_ressource_popup.dart new file mode 100644 index 0000000..5a4f7b8 --- /dev/null +++ b/lib/Screens/Resources/show_ressource_popup.dart @@ -0,0 +1,81 @@ +import 'package:flutter/material.dart'; +import 'package:manager_app/Components/rounded_button.dart'; +import 'package:manager_app/app_context.dart'; +import 'package:manager_app/constants.dart'; +import 'package:managerapi/api.dart'; +import 'package:intl/intl.dart'; + +void showRessource(RessourceDTO ressourceDTO,AppContext appContext, BuildContext context) { + showDialog( + builder: (BuildContext context) => AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(20.0)) + ), + content: SingleChildScrollView( + child: Column( + children: [ + Text(ressourceDTO.label, style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)), + Text('TODO CHARGE IMAGE'), + Text("TODO SHOW IMAGE OR VIDEO") + ], + ), + ), + actions: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Align( + alignment: AlignmentDirectional.bottomEnd, + child: Container( + width: 175, + height: 70, + child: RoundedButton( + text: "Retour", + icon: Icons.undo, + color: kSecond, + press: () { + Navigator.of(context).pop(); + }, + fontSize: 20, + ), + ), + ), + Align( + alignment: AlignmentDirectional.bottomEnd, + child: Container( + width: 200, + height: 70, + child: RoundedButton( + text: "Supprimer", + icon: Icons.delete, + color: kPrimaryColor, + textColor: kWhite, + press: () { + delete(ressourceDTO, appContext, context); + }, + fontSize: 20, + ), + ), + ), + ], + ), + ], + ), context: context + ); +} + +void delete(RessourceDTO ressourceDTO, AppContext appContext, context) async { + if (ressourceDTO.label != null) { + Navigator.of(context).pop(); + + //RessourceDetailDTO newRessource = await appContext.getContext().clientAPI.ressourceApi.ressourceCreate(ressourceDetailDTO); + print("TODO DELETE"); + /*print(newRessource); + + // To refresh only (UGLY COOOOODE) + ManagerAppContext managerAppContext = appContext.getContext(); + appContext.setContext(managerAppContext); + + showNotification(Colors.green, kWhite, 'La ressource a été créée avec succès', context);*/ + } +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 2323672..7386a11 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -71,6 +71,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + file_picker: + dependency: "direct main" + description: + name: file_picker + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + filepicker_windows: + dependency: "direct main" + description: + name: filepicker_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" flutter: dependency: "direct main" description: flutter @@ -83,11 +104,23 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.0" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" http: dependency: transitive description: @@ -109,6 +142,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.16.1" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.3" managerapi: dependency: "direct main" description: @@ -165,6 +205,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.11.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" provider: dependency: "direct main" description: @@ -240,6 +287,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" sdks: dart: ">=2.12.0 <3.0.0" - flutter: ">=1.17.0" + flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index 860ff35..f2deb10 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,6 +32,7 @@ dependencies: material_segmented_control: ^3.1.2 convert: ^3.0.0 collection: any + filepicker_windows: ^2.0.0 managerapi: path: manager_api