import 'dart:convert'; import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'package:manager_api/api.dart'; import 'package:tablet_app/Components/audio_player.dart'; import 'package:tablet_app/Components/video_viewer.dart'; import 'package:tablet_app/Components/video_viewer_youtube.dart'; import 'package:tablet_app/Models/tabletContext.dart'; import 'package:tablet_app/app_context.dart'; showElementForResource(ResourceDTO resourceDTO, AppContext appContext) { TabletAppContext tabletAppContext = appContext.getContext(); Color primaryColor = new Color(int.parse(tabletAppContext.configuration!.primaryColor!.split('(0x')[1].split(')')[0], radix: 16)); switch(resourceDTO.type) { case ResourceType.Image: return Image.network( resourceDTO.url!, fit:BoxFit.fill, loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) { if (loadingProgress == null) { return child; } return Center( child: CircularProgressIndicator( color: primaryColor, value: loadingProgress.expectedTotalBytes != null ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes! : null, ), ); }, ); break; case ResourceType.ImageUrl: return Image.network( resourceDTO.url!, fit:BoxFit.fill, loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) { if (loadingProgress == null) { return child; } return Center( child: CircularProgressIndicator( color: primaryColor, value: loadingProgress.expectedTotalBytes != null ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes! : null, ), ); }, ); case ResourceType.Audio: return AudioPlayerFloatingContainer(audioBytes: null, resourceURl: resourceDTO.url!, isAuto: true); /*return FutureBuilder( future: getAudio(resourceDTO.url, appContext), builder: (context, AsyncSnapshot snapshot) { Size size = MediaQuery.of(context).size; if (snapshot.connectionState == ConnectionState.done) { var audioBytes; if(snapshot.data != null) { print("snapshot.data"); print(snapshot.data); audioBytes = snapshot.data; //this.player.playBytes(audiobytes); } return AudioPlayerFloatingContainer(audioBytes: audioBytes, resourceURl: resourceDTO.url, isAuto: true); } else if (snapshot.connectionState == ConnectionState.none) { return Text("No data"); } else { return Center( child: Container( //height: size.height * 0.2, width: size.width * 0.2, child: LoadingCommon() ) ); } } );*/ case ResourceType.Video: if(resourceDTO.url == null) { return Center(child: Text("Error loading video")); } else { return VideoViewer(videoUrl: resourceDTO.url!); } case ResourceType.VideoUrl: if(resourceDTO.url == null) { return Center(child: Text("Error loading video")); } else { return VideoViewerYoutube(videoUrl: resourceDTO.url!); } } }