diff --git a/lib/Screens/MainView/main_view.dart b/lib/Screens/MainView/main_view.dart index ba8e1bd..d44f148 100644 --- a/lib/Screens/MainView/main_view.dart +++ b/lib/Screens/MainView/main_view.dart @@ -46,7 +46,6 @@ class _MainViewWidget extends State { if(sectionSelected != null) { var elementToShow; - print(sectionSelected!.type); switch (sectionSelected!.type) { case SectionType.map : // MAP elementToShow = ChangeNotifierProvider( @@ -282,9 +281,6 @@ class _MainViewWidget extends State { try { List? sections = await tabletAppContext.clientAPI!.sectionApi!.sectionGetFromConfiguration(tabletAppContext.configuration!.id!); sections!.sort((a, b) => a.order!.compareTo(b.order!)); - - print("Sections"); - print(sections); return sections; } catch (e) { print(e); diff --git a/lib/Screens/Map/google_map_view.dart b/lib/Screens/Map/google_map_view.dart index 296b7a2..361edc9 100644 --- a/lib/Screens/Map/google_map_view.dart +++ b/lib/Screens/Map/google_map_view.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:enum_to_string/enum_to_string.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:manager_api/api.dart'; @@ -53,7 +54,7 @@ class _GoogleMapViewState extends State { double.tryParse(element.latitude!)!, double.tryParse(element.longitude!)!, ), - icon: BitmapDescriptor.fromBytes(widget.selectedMarkerIcon!), + icon: widget.selectedMarkerIcon != null ? BitmapDescriptor.fromBytes(widget.selectedMarkerIcon!) : BitmapDescriptor.defaultMarker, /*icon: BitmapDescriptor.defaultMarkerWithHue( BitmapDescriptor.hueYellow, ),*/ @@ -69,10 +70,9 @@ class _GoogleMapViewState extends State { )); //}); }, - infoWindow: InfoWindow(title: element.title))); + infoWindow: kIsWeb ? InfoWindow.noText : InfoWindow(title: element.title))); } }); - return markers; } @@ -90,17 +90,21 @@ class _GoogleMapViewState extends State { @override Widget build(BuildContext context) { final mapContext = Provider.of(context); - Size size = MediaQuery.of(context).size; + //Size size = MediaQuery.of(context).size; return GoogleMap( mapType: widget.mapDTO!.mapType != null ? EnumToString.fromString(MapType.values, widget.mapDTO!.mapType.toString())!: MapType.hybrid, mapToolbarEnabled: false, initialCameraPosition: CameraPosition( - target: LatLng(50.416639, 4.879169), + target: LatLng(50.465503, 4.865105), // MDLF 50.416639, 4.879169 / Namur 50.465503, 4.865105 zoom: widget.mapDTO!.zoom != null ? widget.mapDTO!.zoom!.toDouble() : 18, ), onMapCreated: (GoogleMapController controller) { - _controller.complete(controller); + if(kIsWeb) { + //_controllerWeb.complete(controller); + } else { + _controller.complete(controller); + } }, markers: getMarkers(widget.language, mapContext), onTap: (LatLng location) { diff --git a/lib/Screens/Map/map_view.dart b/lib/Screens/Map/map_view.dart index 4870974..4594754 100644 --- a/lib/Screens/Map/map_view.dart +++ b/lib/Screens/Map/map_view.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:typed_data'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; @@ -11,9 +12,11 @@ import 'package:tablet_app/Models/map-marker.dart'; import 'dart:ui' as ui; import 'package:flutter/widgets.dart'; import 'package:tablet_app/Screens/Map/marker_view.dart'; +import 'package:http/http.dart' as http; import '../../app_context.dart'; import 'google_map_view.dart'; +import 'package:image/image.dart' as IMG; Set markers = {}; List markersList = []; @@ -28,7 +31,7 @@ class MapViewWidget extends StatefulWidget { class _MapViewWidget extends State { MapDTO? mapDTO; - Completer _controller = Completer(); + //Completer _controller = Completer(); Uint8List? selectedMarkerIcon; Future getBytesFromAsset(ByteData data, int width) async { @@ -43,10 +46,7 @@ class _MapViewWidget extends State { @override void initState() { - print(widget.section!.data); mapDTO = MapDTO.fromJson(jsonDecode(widget.section!.data!)); - print(mapDTO); - super.initState(); } @@ -69,9 +69,12 @@ class _MapViewWidget extends State { return Stack( children: [ FutureBuilder( - future: getByteIcon(mapDTO!.iconSource!), + future: getByteIcon(mapDTO!.iconSource), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { + print("snapshot"); + print(snapshot.data); + print(selectedMarkerIcon); return GoogleMapView(language: appContext.getContext().language, mapDTO: mapDTO!, selectedMarkerIcon: selectedMarkerIcon); } else if (snapshot.connectionState == ConnectionState.none) { return Text("No data"); @@ -94,12 +97,27 @@ class _MapViewWidget extends State { ); } - getByteIcon(String source) async { - final ByteData imageData = await NetworkAssetBundle(Uri.parse(source)).load(""); - selectedMarkerIcon = await getBytesFromAsset(imageData, 50); + getByteIcon(String? source) async { + if(source != null) { + if(kIsWeb) { + Uint8List fileData = await http.readBytes(Uri.parse(source)); + selectedMarkerIcon = resizeImage(fileData, 40); + } else { + final ByteData imageData = await NetworkAssetBundle(Uri.parse(source)).load(""); + selectedMarkerIcon = await getBytesFromAsset(imageData, 50); + } + } } - /*Future _goToTheLake() async { + Uint8List resizeImage(Uint8List data, int width) { + Uint8List resizedData = data; + IMG.Image img = IMG.decodeImage(data)!; + IMG.Image resized = IMG.copyResize(img, width: width); + resizedData = Uint8List.fromList(IMG.encodeJpg(resized)); + return resizedData; + } + +/*Future _goToTheLake() async { final GoogleMapController controller = await _controller.future; controller.animateCamera(CameraUpdate.newCameraPosition(_kLake)); }*/ diff --git a/lib/Screens/Map/marker_view.dart b/lib/Screens/Map/marker_view.dart index bc40c1e..7a2e795 100644 --- a/lib/Screens/Map/marker_view.dart +++ b/lib/Screens/Map/marker_view.dart @@ -1,4 +1,5 @@ import 'package:carousel_slider/carousel_slider.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:photo_view/photo_view.dart'; import 'package:provider/provider.dart'; @@ -98,7 +99,7 @@ class _MarkerInfoWidget extends State { alignment: Alignment.topCenter, child: Padding( padding: const EdgeInsets.only(top: 20), - child: Text(mapContext.getSelectedMarker().title, style: TextStyle(fontWeight: FontWeight.w600, fontSize: kTitleSize)), + child: Text(mapContext.getSelectedMarker().title, style: TextStyle(fontWeight: FontWeight.w600, fontSize: kIsWeb ? kWebTitleSize : kTitleSize)), ), ), Padding( @@ -152,7 +153,7 @@ class _MarkerInfoWidget extends State { child: AspectRatio( aspectRatio: 16 / 9, child: ClipRect( - child: PhotoView( + child: i.imageSource != null ? PhotoView( imageProvider: new NetworkImage( i.imageSource, ), @@ -163,7 +164,7 @@ class _MarkerInfoWidget extends State { shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(15.0), ), - ), + ) : Center(child: Text('No data')), ), ) ), @@ -192,7 +193,7 @@ class _MarkerInfoWidget extends State { child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(15.0), - child: Text(mapContext.getSelectedMarker().description, textAlign: TextAlign.center, style: TextStyle(fontSize: kDescriptionSize)), + child: Text(mapContext.getSelectedMarker().description, textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kWebDescriptionSize : kDescriptionSize)), ), ), ), @@ -209,7 +210,7 @@ class _MarkerInfoWidget extends State { }, child: Icon( Icons.chevron_right, - size: 150, + size: kIsWeb ? 100 : 150, color: kMainRed, ), ) @@ -225,7 +226,7 @@ class _MarkerInfoWidget extends State { }, child: Icon( Icons.chevron_left, - size: 150, + size: kIsWeb ? 100 : 150, color: kMainRed, ), ) diff --git a/lib/Screens/Quizz/quizz_view.dart b/lib/Screens/Quizz/quizz_view.dart index 6d1346e..f62809f 100644 --- a/lib/Screens/Quizz/quizz_view.dart +++ b/lib/Screens/Quizz/quizz_view.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:developer'; import 'package:carousel_slider/carousel_slider.dart'; import 'package:confetti/confetti.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:manager_api/api.dart'; @@ -113,8 +114,8 @@ class _QuizzViewWidget extends State { //height: size.height * 0.2, //width: size.width * 0.25, constraints: BoxConstraints( - maxHeight: size.height * 0.25, - maxWidth: size.width * 0.25, + maxHeight: kIsWeb ? size.height * 0.20 : size.height * 0.25, + maxWidth: kIsWeb ? size.width * 0.20 : size.width * 0.25, ), alignment: Alignment.center, decoration: BoxDecoration( @@ -150,14 +151,14 @@ class _QuizzViewWidget extends State { ), ), Container( - child: Text('$goodResponses/${quizzDTO.questions!.length}', textAlign: TextAlign.center, style: TextStyle(fontSize: 150, color: kBackgroundSecondGrey)), + child: Text('$goodResponses/${quizzDTO.questions!.length}', textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? (showResponses ? 60 : 100) : 150, color: kBackgroundSecondGrey)), ), Container( child: Padding( padding: const EdgeInsets.only(bottom: 10), child: Container( width: MediaQuery.of(context).size.width *0.75, - height: MediaQuery.of(context).size.height *0.25, + height: kIsWeb ? (showResponses ? MediaQuery.of(context).size.height *0.10 : MediaQuery.of(context).size.height *0.20) : MediaQuery.of(context).size.height *0.25, decoration: BoxDecoration( color: kBackgroundLight, shape: BoxShape.rectangle, @@ -177,7 +178,7 @@ class _QuizzViewWidget extends State { child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(15.0), - child: levelToShow != null ? Text(levelToShow.label.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? levelToShow.label.firstWhere((translation) => translation.language == appContext.getContext().language).value : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kDescriptionSize)): Text("No data"), + child: levelToShow != null ? Text(levelToShow.label.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? levelToShow.label.firstWhere((translation) => translation.language == appContext.getContext().language).value : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kWebDescriptionSize : kDescriptionSize)): Text("No data"), ), ), ), @@ -187,27 +188,25 @@ class _QuizzViewWidget extends State { ), if(showResponses) Container( - child: Container( - width: MediaQuery.of(context).size.width *0.75, - height: MediaQuery.of(context).size.height *0.35, - decoration: BoxDecoration( - color: kBackgroundLight, - shape: BoxShape.rectangle, - borderRadius: BorderRadius.circular(10.0), - boxShadow: [ - BoxShadow( - color: kBackgroundSecondGrey, - spreadRadius: 0.3, - blurRadius: 4, - offset: Offset(0, 2), // changes position of shadow - ), - ], - ), - child: Center( - child: Container( - width: double.infinity, - child: ShowReponsesWidget(questionsSubDTO: _questionsSubDTO), + width: MediaQuery.of(context).size.width *0.75, + height: kIsWeb ? MediaQuery.of(context).size.height *0.35 : MediaQuery.of(context).size.height *0.35, + decoration: BoxDecoration( + color: kBackgroundLight, + shape: BoxShape.rectangle, + borderRadius: BorderRadius.circular(10.0), + boxShadow: [ + BoxShadow( + color: kBackgroundSecondGrey, + spreadRadius: 0.3, + blurRadius: 4, + offset: Offset(0, 2), // changes position of shadow ), + ], + ), + child: Center( + child: Container( + width: double.infinity, + child: ShowReponsesWidget(questionsSubDTO: _questionsSubDTO), ), ), ), @@ -218,7 +217,7 @@ class _QuizzViewWidget extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( - height: 85, + height: kIsWeb ? 50 : 85, child: RoundedButton( text: "Recommencer", color: kBackgroundSecondGrey, @@ -232,14 +231,14 @@ class _QuizzViewWidget extends State { _questionsSubDTO = QuestionSubDTO().fromJSON(quizzDTO.questions!); }); }, - fontSize: 30, + fontSize: kIsWeb ? kWebDescriptionSize : 30, horizontal: 30, vertical: 10 ), ), if(!showResponses) Container( - height: 85, + height: kIsWeb ? 50 : 85, child: RoundedButton( text: "Voir les réponses", color: kBackgroundSecondGrey, @@ -250,7 +249,7 @@ class _QuizzViewWidget extends State { showResponses = true; }); }, - fontSize: 30, + fontSize: kIsWeb ? kWebDescriptionSize : 30, horizontal: 30, vertical: 10 ), @@ -343,7 +342,7 @@ class _QuizzViewWidget extends State { child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(15.0), - child: Text(i.label!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.label!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kDescriptionSize)), + child: Text(i.label!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.label!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kWebDescriptionSize : kDescriptionSize)), ), ), ), @@ -368,9 +367,9 @@ class _QuizzViewWidget extends State { child: GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, - mainAxisExtent: 150, - mainAxisSpacing: 150, - crossAxisSpacing: 150, + mainAxisExtent: kIsWeb ? 75 : 150, // TODO depends on percentage + mainAxisSpacing: kIsWeb ? 75 : 150, // TODO depends on percentage + crossAxisSpacing: kIsWeb ? 75 : 150, // TODO depends on percentage ), itemCount: i.responsesSubDTO!.length, itemBuilder: (BuildContext ctx, index) { @@ -381,7 +380,7 @@ class _QuizzViewWidget extends State { if(currentIndex == _questionsSubDTO.length && i.chosen == index) { showResult = true; - _controllerCenter!.play(); + _controllerCenter!.play(); // TODO Maybe show only confetti on super score .. } else { sliderController!.nextPage(duration: new Duration(milliseconds: 650), curve: Curves.fastOutSlowIn); } @@ -391,7 +390,7 @@ class _QuizzViewWidget extends State { padding: const EdgeInsets.all(8.0), child: Container( alignment: Alignment.center, - child: Text(i.responsesSubDTO![index].label!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.responsesSubDTO![index].label!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kDescriptionSize, color: i.chosen == index ? Colors.white : Colors.black)), + child: Text(i.responsesSubDTO![index].label!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.responsesSubDTO![index].label!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kWebDescriptionSize : kDescriptionSize, color: i.chosen == index ? Colors.white : Colors.black)), decoration: BoxDecoration( color: i.chosen == index ? kTestSecondColor : kBackgroundLight, shape: BoxShape.rectangle, @@ -444,7 +443,7 @@ class _QuizzViewWidget extends State { }, child: Icon( Icons.chevron_right, - size: 150, + size: kIsWeb ? 100 : 150, color: kMainRed, ), ) @@ -460,7 +459,7 @@ class _QuizzViewWidget extends State { }, child: Icon( Icons.chevron_left, - size: 150, + size: kIsWeb ? 100 : 150, color: kMainRed, ), ) diff --git a/lib/Screens/Quizz/showResponses.dart b/lib/Screens/Quizz/showResponses.dart index 3e5ecb7..b8d47bd 100644 --- a/lib/Screens/Quizz/showResponses.dart +++ b/lib/Screens/Quizz/showResponses.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'dart:developer'; import 'package:carousel_slider/carousel_slider.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:manager_api/api.dart'; @@ -42,7 +43,7 @@ class _ShowReponsesWidget extends State { Widget build(BuildContext context) { Size sizeAll = MediaQuery.of(context).size; - Size size = Size(sizeAll.width * 0.65, sizeAll.height * 0.32); + Size size = Size(sizeAll.width * 0.65, kIsWeb ? sizeAll.height * 0.5 : sizeAll.height * 0.32); final appContext = Provider.of(context); return Stack( @@ -98,7 +99,8 @@ class _ShowReponsesWidget extends State { padding: const EdgeInsets.all(10.0), child: Container( //width: MediaQuery.of(context).size.width *0.65, - height: size.height *0.25, + //color: Colors.pink, + height: kIsWeb ? size.height *0.25 : size.height *0.25, child: Stack( children: [ Center( @@ -122,7 +124,7 @@ class _ShowReponsesWidget extends State { child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(1.0), - child: Text(i.label!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.label!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kDescriptionSize)), + child: Text(i.label!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.label!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kWebDescriptionSize : kDescriptionSize)), ), ), ), @@ -144,8 +146,8 @@ class _ShowReponsesWidget extends State { child: GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, - mainAxisExtent: 125, - mainAxisSpacing: 15, + mainAxisExtent: kIsWeb ? 65 : 125, // TODO depends on percentage + mainAxisSpacing: kIsWeb ? 10: 15, // TODO depends on percentage crossAxisSpacing: 5, ), itemCount: i.responsesSubDTO!.length, @@ -154,7 +156,7 @@ class _ShowReponsesWidget extends State { padding: const EdgeInsets.all(5.0), child: Container( alignment: Alignment.center, - child: Text(i.responsesSubDTO![index].label!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.responsesSubDTO![index].label!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kDescriptionSize, color: i.chosen == index ? Colors.white : Colors.black)), + child: Text(i.responsesSubDTO![index].label!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.responsesSubDTO![index].label!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kWebDescriptionSize : kDescriptionSize, color: i.chosen == index ? Colors.white : Colors.black)), decoration: BoxDecoration( color: i.responsesSubDTO![index].isGood! ? kGreen : i.chosen == index ? kMainRed : kBackgroundLight, shape: BoxShape.rectangle, @@ -185,8 +187,8 @@ class _ShowReponsesWidget extends State { ), if(_questionsSubDTO != null && _questionsSubDTO.length > 1 && currentIndex != _questionsSubDTO.length && _questionsSubDTO[currentIndex-1].chosen != null && widget.questionsSubDTO!.length > 0) Positioned( - top: size.height * 0.35, - right: 60, + top: kIsWeb ? size.height * 0.3 : size.height * 0.35, // TODO depends on screen' percentage + right: kIsWeb ? 45 : 60, // TODO depends on screen' percentage child: InkWell( onTap: () { if(_questionsSubDTO[currentIndex-1].chosen != null && widget.questionsSubDTO!.length > 0) { @@ -204,15 +206,15 @@ class _ShowReponsesWidget extends State { }, child: Icon( Icons.chevron_right, - size: 150, + size: kIsWeb ? 100 : 150, // TODO depends on screen' percentage color: kMainRed, ), ) ), if(_questionsSubDTO != null && _questionsSubDTO.length > 1 && currentIndex != 1) Positioned( - top: size.height * 0.35, - left: 60, + top: kIsWeb ? size.height * 0.3 : size.height * 0.35, // TODO depends on screen' percentage + left: kIsWeb ? 45 : 60, // TODO depends on screen' percentage child: InkWell( onTap: () { if(currentIndex > 1) @@ -220,7 +222,7 @@ class _ShowReponsesWidget extends State { }, child: Icon( Icons.chevron_left, - size: 150, + size: kIsWeb ? 100 : 150, // TODO depends on screen' percentage color: kMainRed, ), ) diff --git a/lib/Screens/Slider/slider_view.dart b/lib/Screens/Slider/slider_view.dart index 23a6c69..120fc6c 100644 --- a/lib/Screens/Slider/slider_view.dart +++ b/lib/Screens/Slider/slider_view.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:carousel_slider/carousel_slider.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:manager_api/api.dart'; @@ -131,7 +132,7 @@ class _SliderViewWidget extends State { right: 0, child: Padding( padding: const EdgeInsets.all(15.0), - child: Text(i.title!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.title!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kTitleSize, color: kBackgroundLight)), + child: Text(i.title!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.title!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kWebTitleSize : kTitleSize, color: kBackgroundLight)), ) ) ] @@ -160,7 +161,7 @@ class _SliderViewWidget extends State { child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(15.0), - child: Text(i.description!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.description!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kDescriptionSize)), + child: Text(i.description!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null ? i.description!.firstWhere((translation) => translation.language == appContext.getContext().language).value! : "", textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kWebDescriptionSize : kDescriptionSize)), ), ), ), diff --git a/lib/Screens/Video/video_view.dart b/lib/Screens/Video/video_view.dart index 68fbb86..18b7896 100644 --- a/lib/Screens/Video/video_view.dart +++ b/lib/Screens/Video/video_view.dart @@ -1,10 +1,11 @@ import 'dart:convert'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:manager_api/api.dart'; import 'package:tablet_app/constants.dart'; -import 'package:youtube_player_iframe/youtube_player_iframe.dart'; -//import 'package:youtube_player_flutter/youtube_player_flutter.dart'; +import 'package:youtube_player_iframe/youtube_player_iframe.dart' as iframe; +import 'package:youtube_player_flutter/youtube_player_flutter.dart'; class VideoViewWidget extends StatefulWidget { final SectionDTO? section; @@ -15,6 +16,7 @@ class VideoViewWidget extends StatefulWidget { } class _VideoViewWidget extends State { + iframe.YoutubePlayer? _videoViewWeb; YoutubePlayer? _videoView; VideoDTO? videoDTO; @@ -26,61 +28,70 @@ class _VideoViewWidget extends State { String? videoId; if (videoDTO!.source_ != null && videoDTO!.source_!.length > 0 ) { - //videoId = YoutubePlayer.convertUrlToId(videoDTO!.source_!); + videoId = YoutubePlayer.convertUrlToId(videoDTO!.source_!); - final _controller = YoutubePlayerController( - params: YoutubePlayerParams( - mute: false, - showControls: true, - showFullscreenButton: false, - showVideoAnnotations: false, - strictRelatedVideos: true, - pointerEvents: PointerEvents.auto - ), - ); + if (kIsWeb) { + final _controllerWeb = iframe.YoutubePlayerController( + params: iframe.YoutubePlayerParams( + mute: false, + showControls: true, + showFullscreenButton: false, + loop: true, + showVideoAnnotations: false, + strictRelatedVideos: false, + enableKeyboard: false, + enableCaption: false, + pointerEvents: iframe.PointerEvents.auto + ), + ); - _controller.loadVideo(videoDTO!.source_!);//.loadVideoById(videoId: "3vBwRfQbXkg"); // Auto Play + _controllerWeb.loadVideo(videoDTO!.source_!); -// If the requirement is just to play a single video. - /*final _controller = YoutubePlayerController.fromVideoId( - videoId: '', - autoPlay: false, - params: const YoutubePlayerParams(showFullscreenButton: true), - );*/ + _videoViewWeb = iframe.YoutubePlayer( + controller: _controllerWeb, + //showVideoProgressIndicator: false, + /*progressIndicatorColor: Colors.amber, + progressColors: ProgressBarColors( + playedColor: Colors.amber, + handleColor: Colors.amberAccent, + ),*/ + ); + } else { + YoutubePlayerController _controller = YoutubePlayerController( + initialVideoId: videoId!, + flags: YoutubePlayerFlags( + autoPlay: true, + controlsVisibleAtStart: false, + loop: true, + hideControls: false, + hideThumbnail: false, + ), + ); - /*YoutubePlayerController _controller = YoutubePlayerController( - initialVideoId: videoId!, - flags: YoutubePlayerFlags( - autoPlay: true, - controlsVisibleAtStart: false, - loop: true, - hideControls: false, - hideThumbnail: false, - ), - );*/ - _videoView = YoutubePlayer( - controller: _controller, - //showVideoProgressIndicator: false, - /*progressIndicatorColor: Colors.amber, - progressColors: ProgressBarColors( - playedColor: Colors.amber, - handleColor: Colors.amberAccent, - ),*/ - ); + _videoView = YoutubePlayer( + controller: _controller, + //showVideoProgressIndicator: false, + progressIndicatorColor: Colors.amber, + progressColors: ProgressBarColors( + playedColor: Colors.amber, + handleColor: Colors.amberAccent, + ), + ); + } + super.initState(); } - - super.initState(); } @override void dispose() { _videoView = null; + _videoViewWeb = null; super.dispose(); } @override Widget build(BuildContext context) => videoDTO!.source_ != null && videoDTO!.source_!.length > 0 ? - _videoView! : + (kIsWeb ? _videoViewWeb! : _videoView!): Center(child: Text("La vidéo ne peut pas être affichée, l'url est incorrecte", style: new TextStyle(fontSize: kNoneInfoOrIncorrect))); } \ No newline at end of file diff --git a/lib/constants.dart b/lib/constants.dart index 6df99b3..6e3a7af 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -32,6 +32,9 @@ const kWebMenuDescriptionDetailSize = 14.0; const kWebSectionTitleDetailSize = 35.0; const kWebSectionDescriptionDetailSize = 20.0; +const kWebTitleSize = 30.0; +const kWebDescriptionSize = 14.0; + const kNoneInfoOrIncorrect = 35.0; /* diff --git a/web/index.html b/web/index.html index ec9ab2f..44441e4 100644 --- a/web/index.html +++ b/web/index.html @@ -28,6 +28,7 @@ tablet_app +