From ba708274482c2b4eb5147e996a6c5ea1cfe22157 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Tue, 24 Aug 2021 20:21:19 +0200 Subject: [PATCH] Show default message when null or empty --- lib/Screens/Slider/slider_view.dart | 14 +++++++--- lib/Screens/Video/video_view.dart | 41 +++++++++++++++-------------- lib/Screens/Web/web_view.dart | 2 +- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/lib/Screens/Slider/slider_view.dart b/lib/Screens/Slider/slider_view.dart index 009f4ec..60c8b90 100644 --- a/lib/Screens/Slider/slider_view.dart +++ b/lib/Screens/Slider/slider_view.dart @@ -145,12 +145,14 @@ class _SliderViewWidget extends State { ), ], ), - Positioned( + if(sliderDTO.images != null && sliderDTO.images.length > 1) + Positioned( top: MediaQuery.of(context).size.height * 0.35, right: 60, child: InkWell( onTap: () { - sliderController.nextPage(duration: new Duration(milliseconds: 500), curve: Curves.fastOutSlowIn); + if (sliderDTO.images.length > 0) + sliderController.nextPage(duration: new Duration(milliseconds: 500), curve: Curves.fastOutSlowIn); }, child: Icon( Icons.chevron_right, @@ -159,12 +161,14 @@ class _SliderViewWidget extends State { ), ) ), - Positioned( + if(sliderDTO.images != null && sliderDTO.images.length > 1) + Positioned( top: MediaQuery.of(context).size.height * 0.35, left: 60, child: InkWell( onTap: () { - sliderController.previousPage(duration: new Duration(milliseconds: 500), curve: Curves.fastOutSlowIn); + if (sliderDTO.images.length > 0) + sliderController.previousPage(duration: new Duration(milliseconds: 500), curve: Curves.fastOutSlowIn); }, child: Icon( Icons.chevron_left, @@ -189,6 +193,8 @@ class _SliderViewWidget extends State { ) ), ), + if(sliderDTO.images == null || sliderDTO.images.length == 0) + Center(child: Text("Aucune image à afficher")) // Description /*Container( height: sliderDTO.images != null && sliderDTO.images.length > 0 ? size.height *0.3 : size.height *0.6, diff --git a/lib/Screens/Video/video_view.dart b/lib/Screens/Video/video_view.dart index 791e34b..e2ed452 100644 --- a/lib/Screens/Video/video_view.dart +++ b/lib/Screens/Video/video_view.dart @@ -23,31 +23,32 @@ class _VideoViewWidget extends State { print(videoDTO); String videoId; - videoId = YoutubePlayer.convertUrlToId(videoDTO.source_); - print(videoId); + if (videoDTO.source_ != null && videoDTO.source_.length > 0 ) { + videoId = YoutubePlayer.convertUrlToId(videoDTO.source_); - super.initState(); + 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, + _videoView = YoutubePlayer( + controller: _controller, + showVideoProgressIndicator: false, + /*progressIndicatorColor: Colors.amber, progressColors: ProgressBarColors( playedColor: Colors.amber, handleColor: Colors.amberAccent, ),*/ - ); + ); + } + + super.initState(); } @override @@ -57,5 +58,5 @@ class _VideoViewWidget extends State { } @override - Widget build(BuildContext context) => _videoView; + Widget build(BuildContext context) => videoDTO.source_ != null && videoDTO.source_.length > 0 ? _videoView : Center(child: Text("La vidéo ne peut pas être affichée, l'url est incorrecte")); } \ No newline at end of file diff --git a/lib/Screens/Web/web_view.dart b/lib/Screens/Web/web_view.dart index 48fa2f7..cbc3e0f 100644 --- a/lib/Screens/Web/web_view.dart +++ b/lib/Screens/Web/web_view.dart @@ -45,5 +45,5 @@ class _WebViewWidget extends State { } @override - Widget build(BuildContext context) => _webView; + Widget build(BuildContext context) => webDTO.source_ != null && webDTO.source_.length > 0 ? _webView : Center(child: Text("La page internet ne peut pas être affichée, l'url est incorrecte ou vide")); } \ No newline at end of file