From a69d1aa03f9b464cc9c07b5927a85c0c43c9cf8d Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Fri, 19 Nov 2021 18:54:52 +0100 Subject: [PATCH 1/4] WEB - WIP --- lib/Components/resource_tab.dart | 2 +- lib/Components/upload_image_container.dart | 11 +- lib/Components/vlc_viewer.dart | 7 +- lib/Helpers/FileHelper.dart | 6 +- .../Slider/listView_card_image.dart | 2 +- .../SubSection/Slider/slider_config.dart | 4 +- .../Section/section_detail_screen.dart | 4 +- .../new_configuration_popup.dart | 7 +- lib/Screens/login_screen.dart | 3 + lib/client.dart | 2 + lib/main.dart | 21 ++- linux/flutter/generated_plugin_registrant.cc | 8 - linux/flutter/generated_plugins.cmake | 2 - macos/Flutter/GeneratedPluginRegistrant.swift | 4 - pubspec.lock | 156 ------------------ pubspec.yaml | 18 +- .../flutter/generated_plugin_registrant.cc | 6 - windows/flutter/generated_plugins.cmake | 2 - 18 files changed, 53 insertions(+), 212 deletions(-) diff --git a/lib/Components/resource_tab.dart b/lib/Components/resource_tab.dart index 6aee23f..a757281 100644 --- a/lib/Components/resource_tab.dart +++ b/lib/Components/resource_tab.dart @@ -1,8 +1,8 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:manager_app/Components/upload_image_container.dart'; import 'package:manager_app/Components/upload_online_resources_container.dart'; -import 'file:///C:/Users/Thomas%20Fransolet/Documents/Documents/Perso/MuseeDeLaFraise/manager-app/lib/Components/upload_image_container.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; class ResourceTab extends StatefulWidget { diff --git a/lib/Components/upload_image_container.dart b/lib/Components/upload_image_container.dart index 75370be..0673b1a 100644 --- a/lib/Components/upload_image_container.dart +++ b/lib/Components/upload_image_container.dart @@ -1,8 +1,8 @@ import 'dart:io'; -import 'package:dart_vlc/dart_vlc.dart'; +//import 'package:dart_vlc/dart_vlc.dart'; import 'package:manager_app/Components/loading.dart'; import 'package:manager_app/constants.dart'; -import 'package:filepicker_windows/filepicker_windows.dart'; +//import 'package:filepicker_windows/filepicker_windows.dart'; import 'package:flutter/material.dart'; class UploadImageContainer extends StatefulWidget { @@ -40,7 +40,7 @@ class _UploadImageContainerState extends State with Single } void filePicker() { - final file = OpenFilePicker() + /*final file = OpenFilePicker() ..filterSpecification = { 'Images (*.jpg; *.png)': '*.jpg;*.png', //'Video (*.mp4)': '*.mp4', @@ -58,7 +58,7 @@ class _UploadImageContainerState extends State with Single fileToShow = result; widget.onChanged(result); }); - } + }*/ } showFile() { @@ -111,7 +111,8 @@ class _UploadImageContainerState extends State with Single } loadFile(File fileToShow) async { - return await Media.file(fileToShow); + //return await Media.file(fileToShow); + return null; } displayElement() { diff --git a/lib/Components/vlc_viewer.dart b/lib/Components/vlc_viewer.dart index 2c654ec..4e746d7 100644 --- a/lib/Components/vlc_viewer.dart +++ b/lib/Components/vlc_viewer.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:dart_vlc/dart_vlc.dart'; - +//import 'package:dart_vlc/dart_vlc.dart'; +/* class DartVLC extends StatefulWidget { final Media file; const DartVLC({ @@ -734,4 +734,5 @@ class _DartVLCState extends State { ), );*/ } -} \ No newline at end of file +} +*/ diff --git a/lib/Helpers/FileHelper.dart b/lib/Helpers/FileHelper.dart index 305e830..f1cbf4b 100644 --- a/lib/Helpers/FileHelper.dart +++ b/lib/Helpers/FileHelper.dart @@ -7,7 +7,7 @@ import 'package:manager_app/Models/session.dart'; import 'package:manager_app/client.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; -import 'package:path_provider/path_provider.dart'; +//import 'package:path_provider/path_provider.dart'; class FileHelper { final key = Key.fromUtf8('aVs:ZMe3EK-ySvCGrj3T8]yG6E'); @@ -15,8 +15,8 @@ class FileHelper { Future get _localPath async { - final directory = await getApplicationDocumentsDirectory(); - + //final directory = await getApplicationDocumentsDirectory(); + var directory; return directory.path; } diff --git a/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart b/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart index 109f3c7..b66b736 100644 --- a/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart +++ b/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart @@ -1,6 +1,6 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; -import 'file:///C:/Users/Thomas%20Fransolet/Documents/Documents/Perso/MuseeDeLaFraise/manager-app/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.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'; diff --git a/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart b/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart index 51ff1ff..6134801 100644 --- a/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart @@ -1,7 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'file:///C:/Users/Thomas%20Fransolet/Documents/Documents/Perso/MuseeDeLaFraise/manager-app/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart'; -import 'file:///C:/Users/Thomas%20Fransolet/Documents/Documents/Perso/MuseeDeLaFraise/manager-app/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.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'; diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index 27cf8f2..a340f27 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -8,8 +8,7 @@ import 'package:manager_app/Components/multi_string_input_container.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 'file:///C:/Users/Thomas%20Fransolet/Documents/Documents/Perso/MuseeDeLaFraise/manager-app/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart'; -import 'file:///C:/Users/Thomas%20Fransolet/Documents/Documents/Perso/MuseeDeLaFraise/manager-app/lib/Screens/Configurations/Section/SubSection/WebOrVideo/web_video_config.dart'; +import 'package:manager_app/Screens/Configurations/Section/SubSection/WebOrVideo/web_video_config.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/client.dart'; import 'package:manager_app/constants.dart'; @@ -19,6 +18,7 @@ import 'package:intl/intl.dart'; import 'SubSection/Map/map_config.dart'; import 'SubSection/Menu/menu_config.dart'; +import 'SubSection/Slider/slider_config.dart'; class SectionDetailScreen extends StatefulWidget { final String id; diff --git a/lib/Screens/Configurations/new_configuration_popup.dart b/lib/Screens/Configurations/new_configuration_popup.dart index 9cdc0b2..aa856de 100644 --- a/lib/Screens/Configurations/new_configuration_popup.dart +++ b/lib/Screens/Configurations/new_configuration_popup.dart @@ -1,4 +1,4 @@ -import 'package:filepicker_windows/filepicker_windows.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'; @@ -106,7 +106,7 @@ void showNewConfiguration(AppContext appContext, ValueChanged isImport, Bu } String filePicker() { - final file = OpenFilePicker() + /*final file = OpenFilePicker() ..filterSpecification = { 'Fichier (*.json)': '*.json', //'Video (*.mp4)': '*.mp4', @@ -115,7 +115,8 @@ String filePicker() { ..defaultFilterIndex = 0 ..title = 'Sélectionner un fichier'; - final result = file.getFile(); + final result = file.getFile();*/ + var result; return result != null ? result.path : null; } diff --git a/lib/Screens/login_screen.dart b/lib/Screens/login_screen.dart index 4e5eb52..f0e9eac 100644 --- a/lib/Screens/login_screen.dart +++ b/lib/Screens/login_screen.dart @@ -44,6 +44,9 @@ class _LoginScreenState extends State { setState(() { isLoading = true; }); + print(email); + print(password); + LoginDTO loginDTO = new LoginDTO(email: email, password: password); TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO); print("Token ??"); diff --git a/lib/client.dart b/lib/client.dart index 52a6241..3f8c72b 100644 --- a/lib/client.dart +++ b/lib/client.dart @@ -26,7 +26,9 @@ class Client { Client(String path) { _apiClient = ApiClient( basePath: path); + //basePath: "https://192.168.31.140"); //basePath: "https://localhost:44339"); + _apiClient.addDefaultHeader("Access-Control_Allow_Origin", "*"); _authenticationApi = AuthenticationApi(_apiClient); _userApi = UserApi(_apiClient); _configurationApi = ConfigurationApi(_apiClient); diff --git a/lib/main.dart b/lib/main.dart index da45783..50eba52 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'dart:ui'; import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Main/main_screen.dart'; @@ -9,17 +10,17 @@ import 'Models/session.dart'; import 'Screens/login_screen.dart'; import 'app_context.dart'; import 'constants.dart'; -import 'package:window_size/window_size.dart'; +//import 'package:window_size/window_size.dart'; Future main() async { String initialRoute; WidgetsFlutterBinding.ensureInitialized(); - if (Platform.isWindows) { - setWindowTitle("Manager"); + /*if (Platform.isWindows) { + /*setWindowTitle("Manager"); setWindowMinSize(Size(1250, 850)); - setWindowMaxSize(Size(3840, 2160)); - } + setWindowMaxSize(Size(3840, 2160));*/ + }*/ initialRoute = '/welcome'; @@ -51,6 +52,7 @@ class _MyAppState extends State { return ChangeNotifierProvider( create: (_) => AppContext(widget.managerAppContext), child: MaterialApp( + scrollBehavior: MyCustomScrollBehavior(), debugShowCheckedModeBanner: false, title: 'Manager App Demo', initialRoute: widget.initialRoute, @@ -80,3 +82,12 @@ Future loadJsonSessionFile() async { return session; } +class MyCustomScrollBehavior extends MaterialScrollBehavior { + // Override behavior methods and getters like dragDevices + @override + Set get dragDevices => { + PointerDeviceKind.touch, + PointerDeviceKind.mouse, + }; +} + diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 08653c4..e71a16d 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,14 +6,6 @@ #include "generated_plugin_registrant.h" -#include -#include void fl_register_plugins(FlPluginRegistry* registry) { - g_autoptr(FlPluginRegistrar) dart_vlc_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "DartVlcPlugin"); - dart_vlc_plugin_register_with_registrar(dart_vlc_registrar); - g_autoptr(FlPluginRegistrar) window_size_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "WindowSizePlugin"); - window_size_plugin_register_with_registrar(window_size_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 53f2011..51436ae 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,8 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - dart_vlc - window_size ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 73ed95b..cccf817 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,10 +5,6 @@ import FlutterMacOS import Foundation -import path_provider_macos -import window_size func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { - PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) - WindowSizePlugin.register(with: registry.registrar(forPlugin: "WindowSizePlugin")) } diff --git a/pubspec.lock b/pubspec.lock index 43e7f20..97813ad 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,13 +1,6 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - ansicolor: - dependency: transitive - description: - name: ansicolor - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" args: dependency: transitive description: @@ -29,13 +22,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.8.2" - audio_video_progress_bar: - dependency: transitive - description: - name: audio_video_progress_bar - url: "https://pub.dartlang.org" - source: hosted - version: "0.4.0" auto_size_text: dependency: "direct main" description: @@ -99,20 +85,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.3" - dart_vlc: - dependency: "direct main" - description: - name: dart_vlc - url: "https://pub.dartlang.org" - source: hosted - version: "0.0.9" - dart_vlc_ffi: - dependency: transitive - description: - name: dart_vlc_ffi - url: "https://pub.dartlang.org" - source: hosted - version: "0.0.9" drag_and_drop_lists: dependency: "direct main" description: @@ -134,27 +106,6 @@ 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.1.2" - file: - dependency: transitive - description: - name: file - url: "https://pub.dartlang.org" - source: hosted - version: "6.1.2" - filepicker_windows: - dependency: "direct main" - description: - name: filepicker_windows - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" flare_flutter: dependency: "direct main" description: @@ -198,13 +149,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.4" - injector: - dependency: transitive - description: - name: injector - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" intl: dependency: transitive description: @@ -247,13 +191,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.7.0" - msix: - dependency: "direct main" - description: - name: msix - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.3" multiselect_formfield: dependency: "direct main" description: @@ -268,13 +205,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" - package_config: - dependency: transitive - description: - name: package_config - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" path: dependency: transitive description: @@ -282,41 +212,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" - path_provider: - dependency: "direct main" - description: - name: path_provider - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.2" - path_provider_linux: - dependency: transitive - description: - name: path_provider_linux - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.2" - path_provider_macos: - dependency: transitive - description: - name: path_provider_macos - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.2" - path_provider_platform_interface: - dependency: transitive - description: - name: path_provider_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" - path_provider_windows: - dependency: transitive - description: - name: path_provider_windows - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.3" pedantic: dependency: transitive description: @@ -324,20 +219,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.11.1" - platform: - dependency: transitive - description: - name: platform - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.2" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" pointycastle: dependency: transitive description: @@ -345,13 +226,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.3.1" - process: - dependency: transitive - description: - name: process - url: "https://pub.dartlang.org" - source: hosted - version: "4.2.3" provider: dependency: "direct main" description: @@ -448,36 +322,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.3" - win32: - dependency: transitive - description: - name: win32 - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" - window_size: - dependency: "direct main" - description: - path: "plugins/window_size" - ref: "927f8cbc09b35d85245c095f2db8df9b186f6618" - resolved-ref: "927f8cbc09b35d85245c095f2db8df9b186f6618" - url: "git://github.com/google/flutter-desktop-embedding.git" - source: git - version: "0.1.0" - xdg_directories: - dependency: transitive - description: - name: xdg_directories - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0" - yaml: - dependency: transitive - description: - name: yaml - url: "https://pub.dartlang.org" - source: hosted - version: "3.1.0" sdks: dart: ">=2.12.0 <3.0.0" flutter: ">=2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 058e4c4..c108259 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,19 +32,19 @@ dependencies: material_segmented_control: ^3.1.2 convert: ^3.0.0 collection: any - filepicker_windows: ^2.0.0 + #filepicker_windows: ^2.0.0 flare_flutter: ^3.0.1 - dart_vlc: ^0.0.6 + #dart_vlc: ^0.0.6 video_player: ^2.1.1 drag_and_drop_lists: ^0.3.2 - path_provider: ^2.0.2 + #path_provider: ^2.0.2 encrypt: ^5.0.0 - msix: ^2.1.3 - window_size: - git: - url: git://github.com/google/flutter-desktop-embedding.git - path: plugins/window_size - ref: 927f8cbc09b35d85245c095f2db8df9b186f6618 + #msix: ^2.1.3 + #window_size: + # git: + # url: git://github.com/google/flutter-desktop-embedding.git + # path: plugins/window_size + # ref: 927f8cbc09b35d85245c095f2db8df9b186f6618 managerapi: path: manager_api diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 36f9252..8b6d468 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,12 +6,6 @@ #include "generated_plugin_registrant.h" -#include -#include void RegisterPlugins(flutter::PluginRegistry* registry) { - DartVlcPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("DartVlcPlugin")); - WindowSizePluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("WindowSizePlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index bb61159..4d10c25 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,8 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - dart_vlc - window_size ) set(PLUGIN_BUNDLED_LIBRARIES) From f9405eb842a8a39a0e0cd4ad85f58ef8993f41d5 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Fri, 19 Nov 2021 18:59:49 +0100 Subject: [PATCH 2/4] Help debug --- lib/Screens/login_screen.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Screens/login_screen.dart b/lib/Screens/login_screen.dart index f0e9eac..064f13a 100644 --- a/lib/Screens/login_screen.dart +++ b/lib/Screens/login_screen.dart @@ -32,8 +32,10 @@ class _LoginScreenState extends State { void authenticateTRY(dynamic appContext) async { print("try auth.. "); - print(this.email); - print(this.password); + + this.host = "http://localhost:5000"; + this.email = "fs"; + this.password = "fs"; clientAPI = Client(this.host); From 6b2c74424a26b2c2901e52717aed4a61f82fe7f1 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Thu, 23 Dec 2021 11:53:36 +0100 Subject: [PATCH 3/4] Add filepicker +update size image section --- lib/Components/image_input_container.dart | 4 ++-- pubspec.lock | 28 +++++++++++++++++++++++ pubspec.yaml | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/Components/image_input_container.dart b/lib/Components/image_input_container.dart index 15fe508..c081571 100644 --- a/lib/Components/image_input_container.dart +++ b/lib/Components/image_input_container.dart @@ -48,7 +48,7 @@ class _ImageInputContainerState extends State { child: Text(widget.label, style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)) ), Padding( - padding: EdgeInsets.only(left: widget.isSmall ? 15 : 50, top: 10, bottom: 10), + padding: EdgeInsets.only(left: widget.isSmall ? 15 : 70, top: 10, bottom: 10), child: Container( width: size.width *0.08, child: InkWell( @@ -85,7 +85,7 @@ class _ImageInputContainerState extends State { builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { return Transform.scale( - scale: isSmall ? size.aspectRatio * 0.5: size.aspectRatio, + scale: isSmall ? size.aspectRatio * 0.5: size.aspectRatio * 0.9, child: AspectRatio( aspectRatio: 4/4, child: Container( diff --git a/pubspec.lock b/pubspec.lock index 97813ad..bb18f7c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -106,6 +106,20 @@ 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.1.2" + file_picker: + dependency: "direct main" + description: + name: file_picker + url: "https://pub.dartlang.org" + source: hosted + version: "4.3.0" flare_flutter: dependency: "direct main" description: @@ -125,6 +139,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.0" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" flutter_test: dependency: "direct dev" description: flutter @@ -219,6 +240,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.11.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" pointycastle: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c108259..196c2c4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,6 +33,7 @@ dependencies: convert: ^3.0.0 collection: any #filepicker_windows: ^2.0.0 + file_picker: ^4.3.0 flare_flutter: ^3.0.1 #dart_vlc: ^0.0.6 video_player: ^2.1.1 From 54091ea2db0c80048654347d8ac36338b1ea02fb Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Thu, 23 Dec 2021 13:48:46 +0100 Subject: [PATCH 4/4] upload multiple files Windows and Web + if web no remember me --- lib/Components/resource_tab.dart | 17 ++-- lib/Components/upload_image_container.dart | 77 ++++++++++++++----- lib/Screens/Resources/new_resource_popup.dart | 17 ++-- lib/Screens/Resources/resources_screen.dart | 44 +++++++---- lib/Screens/login_screen.dart | 6 +- lib/main.dart | 5 -- 6 files changed, 112 insertions(+), 54 deletions(-) diff --git a/lib/Components/resource_tab.dart b/lib/Components/resource_tab.dart index a757281..72b6c0e 100644 --- a/lib/Components/resource_tab.dart +++ b/lib/Components/resource_tab.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/upload_image_container.dart'; import 'package:manager_app/Components/upload_online_resources_container.dart'; @@ -8,10 +9,12 @@ import 'package:managerapi/api.dart'; class ResourceTab extends StatefulWidget { final ResourceDTO resourceDTO; final Function onFileUpload; + final Function onFileUploadWeb; const ResourceTab({ Key key, this.resourceDTO, this.onFileUpload, + this.onFileUploadWeb, }) : super(key: key); @override @@ -51,7 +54,7 @@ class _ResourceTabState extends State with SingleTickerProviderStat ), Expanded( child: TabBarView( - children: getContent(widget.resourceDTO, widget.onFileUpload), + children: getContent(widget.resourceDTO, widget.onFileUpload, widget.onFileUploadWeb), controller: _tabController, ), ), @@ -85,7 +88,7 @@ class _ResourceTabState extends State with SingleTickerProviderStat } } -getContent(ResourceDTO resourceDTO, Function onFileUpload) { +getContent(ResourceDTO resourceDTO, Function onFileUpload, Function onFileUploadWeb) { List tabsToShow = new List(); // Local Image @@ -93,10 +96,14 @@ getContent(ResourceDTO resourceDTO, Function onFileUpload) { new Padding( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16), child: UploadImageContainer( - onChanged: (File file) { - onFileUpload(file); + onChanged: (List files) { + onFileUpload(files); resourceDTO.type = ResourceType.image; - } + }, + onChangedWeb: (List files) { + onFileUploadWeb(files); + resourceDTO.type = ResourceType.image; + }, ), ) ); diff --git a/lib/Components/upload_image_container.dart b/lib/Components/upload_image_container.dart index 0673b1a..73fd2a9 100644 --- a/lib/Components/upload_image_container.dart +++ b/lib/Components/upload_image_container.dart @@ -1,15 +1,18 @@ import 'dart:io'; -//import 'package:dart_vlc/dart_vlc.dart'; +import 'dart:typed_data'; +import 'package:file_picker/file_picker.dart'; import 'package:manager_app/Components/loading.dart'; import 'package:manager_app/constants.dart'; -//import 'package:filepicker_windows/filepicker_windows.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart' show kIsWeb; class UploadImageContainer extends StatefulWidget { - final ValueChanged onChanged; + final ValueChanged> onChanged; + final ValueChanged> onChangedWeb; const UploadImageContainer({ Key key, this.onChanged, + this.onChangedWeb, }) : super(key: key); @override @@ -19,6 +22,7 @@ class UploadImageContainer extends StatefulWidget { class _UploadImageContainerState extends State with SingleTickerProviderStateMixin { var filePath; File fileToShow; + String fileToShowWeb; @override void initState() { @@ -39,7 +43,41 @@ class _UploadImageContainerState extends State with Single return (filePath.toString().split('\\').last); } - void filePicker() { + Future filePicker() async { + FilePickerResult result; + if (kIsWeb) { + result = await FilePicker.platform.pickFiles( + type: FileType.custom, + dialogTitle: 'Sélectionner un fichier', + allowMultiple: true, + allowedExtensions: ['jpg', 'jpeg', 'png'], + ); + + if (result != null) { + List files = result.files; + + setState(() { + filePath = "Fichiers"; // Only show one picture + fileToShowWeb = "Aucun aperçu possible"; // Only show one picture + widget.onChangedWeb(files); + }); + } + } else { + result = await FilePicker.platform.pickFiles( + type: FileType.custom, + dialogTitle: 'Sélectionner un fichier', + allowMultiple: true, + allowedExtensions: ['jpg', 'jpeg', 'png'], + ); + + List files = result.paths.map((path) => File(path)).toList(); + var file = files[0]; + setState(() { + filePath = file.path; // Only show one picture + fileToShow = file; // Only show one picture + widget.onChanged(files); + }); + } /*final file = OpenFilePicker() ..filterSpecification = { 'Images (*.jpg; *.png)': '*.jpg;*.png', @@ -63,8 +101,7 @@ class _UploadImageContainerState extends State with Single showFile() { if (getFileName(filePath).contains(".mp4")) { - - return FutureBuilder( + /*return FutureBuilder( future: loadFile(fileToShow), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { @@ -96,27 +133,27 @@ class _UploadImageContainerState extends State with Single ); } } - ); - - - - /*await Media.file(widget.file)*/ + );*/ } else { - return Image.file( - fileToShow, - height: 200, - fit:BoxFit.scaleDown - ); + if (kIsWeb) { + return null; + } else { + return Image.file( + fileToShow, + height: 200, + fit:BoxFit.scaleDown + ); + } } } loadFile(File fileToShow) async { //return await Media.file(fileToShow); - return null; + return null; // Useless no mp4 for now } displayElement() { - if (fileToShow == null) return Center( + if (fileToShow == null && fileToShowWeb == null) return Center( child: InkWell( onTap: () async { filePicker(); @@ -129,14 +166,14 @@ class _UploadImageContainerState extends State with Single child: Padding( padding: const EdgeInsets.only(left: 25.0, right: 25.0, top: 15.0, bottom: 15.0), child: Text( - "Ajouter un fichier", + "Ajouter un ou plusieurs fichiers", style: new TextStyle(color: kWhite), ), ) ), ), ); - if (fileToShow != null) + if (fileToShow != null || fileToShowWeb != null) return Container( margin: EdgeInsets.all(8.0), child: Card( diff --git a/lib/Screens/Resources/new_resource_popup.dart b/lib/Screens/Resources/new_resource_popup.dart index 56a00bc..b09f3e1 100644 --- a/lib/Screens/Resources/new_resource_popup.dart +++ b/lib/Screens/Resources/new_resource_popup.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:file_picker/file_picker.dart'; import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/resource_tab.dart'; import 'package:flutter/material.dart'; @@ -13,7 +14,8 @@ dynamic showNewResource(AppContext appContext, BuildContext context) async { ResourceDTO resourceDetailDTO = new ResourceDTO(); Size size = MediaQuery.of(context).size; var fileName; - File fileToSend; + List filesToSend; + List filesToSendWeb; var result = await showDialog( builder: (BuildContext context) => AlertDialog( @@ -43,8 +45,11 @@ dynamic showNewResource(AppContext appContext, BuildContext context) async { height: size.height *0.5, child: ResourceTab( resourceDTO: resourceDetailDTO, - onFileUpload: (File file) { - fileToSend = file; + onFileUpload: (List files) { + filesToSend = files; + }, + onFileUploadWeb: (List files) { + filesToSendWeb = files; }, ) ), @@ -83,9 +88,9 @@ dynamic showNewResource(AppContext appContext, BuildContext context) async { color: kPrimaryColor, textColor: kWhite, press: () { - if (resourceDetailDTO.label != null) { - if (resourceDetailDTO.data != null || fileToSend != null) { - Navigator.pop(context, [resourceDetailDTO, fileToSend]); + if (resourceDetailDTO.label != null && resourceDetailDTO.label.trim() != '') { + if (resourceDetailDTO.data != null || filesToSendWeb.length > 0 || filesToSend.length > 0) { + Navigator.pop(context, [resourceDetailDTO, filesToSend, filesToSendWeb]); } else { showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context, null); } diff --git a/lib/Screens/Resources/resources_screen.dart b/lib/Screens/Resources/resources_screen.dart index 64939db..c13faa7 100644 --- a/lib/Screens/Resources/resources_screen.dart +++ b/lib/Screens/Resources/resources_screen.dart @@ -1,6 +1,7 @@ import 'dart:convert'; +import 'dart:developer'; import 'dart:io'; - +import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/loading.dart'; import 'package:manager_app/Components/message_notification.dart'; @@ -13,6 +14,7 @@ import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; import 'package:provider/provider.dart'; import 'package:http/http.dart' as http; +import 'package:flutter/foundation.dart' show kIsWeb; class ResourcesScreen extends StatefulWidget { final Function onGetResult; //return ResourceDTO @@ -51,7 +53,7 @@ class _ResourcesScreenState extends State { var result = await showNewResource(appContext, context); if (result != null) { - await create(result[0], result[1], appContext, context); + await create(result[0], result[1], result[2], appContext, context); setState(() {}); // For refresh } } else { @@ -85,19 +87,35 @@ Future getResources(Function onGetResult, bool isImage, dynamic appContext return resources; } -Future create(ResourceDTO resourceDTO, File file, AppContext appContext, context) async { +Future create(ResourceDTO resourceDTO, List files, List filesWeb, AppContext appContext, context) async { switch(resourceDTO.type) { case ResourceType.image: case ResourceType.video: + var request = http.MultipartRequest('POST', Uri.parse(appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/upload")); - request.files.add( - await http.MultipartFile( - 'picture', - file.readAsBytes().asStream(), - file.lengthSync(), - filename: file.path.toString().split("/").last - ) - ); + + if (kIsWeb) { + for (PlatformFile file in filesWeb) { + request.files.add( + await http.MultipartFile.fromBytes( + 'picture', + file.bytes, + filename: file.name + ) + ); + } + } else { + for (File file in files) { + request.files.add( + await http.MultipartFile( + 'picture', + file.readAsBytes().asStream(), + file.lengthSync(), + filename: file.path.toString().split("/").last + ) + ); + } + } ManagerAppContext managerAppContext = appContext.getContext(); request.headers["authorization"]="Bearer ${managerAppContext.token.accessToken}"; @@ -108,10 +126,8 @@ Future create(ResourceDTO resourceDTO, File file, AppContext appCon final respStr = await res.stream.bytesToString(); if (res.statusCode == 200) { - var result = ResourceDTO.fromJson(jsonDecode(respStr)); showNotification(Colors.green, kWhite, 'La ressource a été créée avec succès', context, null); - - return result; + return null; } else { showNotification(kPrimaryColor, kWhite, 'Une erreur est survenue lors de la création de la ressource', context, null); } diff --git a/lib/Screens/login_screen.dart b/lib/Screens/login_screen.dart index 064f13a..c860245 100644 --- a/lib/Screens/login_screen.dart +++ b/lib/Screens/login_screen.dart @@ -13,6 +13,7 @@ import 'package:manager_app/client.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; import 'package:provider/provider.dart'; +import 'package:flutter/foundation.dart' show kIsWeb; class LoginScreen extends StatefulWidget { final Session session; @@ -51,9 +52,6 @@ class _LoginScreenState extends State { LoginDTO loginDTO = new LoginDTO(email: email, password: password); TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO); - print("Token ??"); - print(token); - print(token.accessToken); setAccessToken(token.accessToken); if (isRememberMe) { @@ -172,7 +170,7 @@ class _LoginScreenState extends State { password = value; }, ), - Padding( + if(!kIsWeb) Padding( padding: const EdgeInsets.all(8.0), child: Row( crossAxisAlignment: CrossAxisAlignment.center, diff --git a/lib/main.dart b/lib/main.dart index 50eba52..8e7413b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,11 +16,6 @@ Future main() async { String initialRoute; WidgetsFlutterBinding.ensureInitialized(); - /*if (Platform.isWindows) { - /*setWindowTitle("Manager"); - setWindowMinSize(Size(1250, 850)); - setWindowMaxSize(Size(3840, 2160));*/ - }*/ initialRoute = '/welcome';