124 lines
4.3 KiB
Dart
124 lines
4.3 KiB
Dart
|
|
import 'package:manager_app/Components/audio_player.dart';
|
|
import 'package:manager_app/Components/video_viewer.dart';
|
|
import 'package:manager_app/app_context.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
getElementForResource(dynamic resourceDTO, AppContext appContext) {
|
|
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: kPrimaryColor,
|
|
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: kPrimaryColor,
|
|
value: loadingProgress.expectedTotalBytes != null
|
|
? loadingProgress.cumulativeBytesLoaded /
|
|
loadingProgress.expectedTotalBytes!
|
|
: null,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
break;
|
|
case ResourceType.Audio:
|
|
return AudioPlayerFloatingContainer(audioBytes: null, resourceURl: resourceDTO.url, isAuto: true);
|
|
/*return FutureBuilder(
|
|
future: getAudio(resourceDTO.url, appContext),
|
|
builder: (context, AsyncSnapshot<dynamic> 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()
|
|
)
|
|
);
|
|
}
|
|
}
|
|
);*/
|
|
//return Text("Fichier audio - aucune visualisation possible");
|
|
case ResourceType.Video:
|
|
if(resourceDTO.url == null) {
|
|
return Center(child: Text("Error loading video"));
|
|
} else {
|
|
return VideoViewer(videoUrl: resourceDTO.url!);
|
|
}
|
|
|
|
case ResourceType.VideoUrl:
|
|
return SelectableText(resourceDTO.url!);
|
|
|
|
/*case ResourceType.VideoUrl:
|
|
if(resourceDTO.url == null) {
|
|
return Center(child: Text("Error loading video"));
|
|
} else {
|
|
return VideoViewerYoutube(videoUrl: resourceDTO.url!);
|
|
}*/ // TODO
|
|
|
|
case ResourceType.Pdf:
|
|
return Text("Fichier pdf - aucune visualisation possible");
|
|
|
|
case ResourceType.Json:
|
|
return Text("Fichier json - aucune visualisation possible");
|
|
|
|
case ResourceType.JsonUrl:
|
|
return SelectableText(resourceDTO.url!);
|
|
}
|
|
}
|
|
|
|
/*Future<Uint8List?> getAudio(String resourceId, AppContext appContext) async {
|
|
try {
|
|
ManagerAppContext managerAppContext = appContext.getContext() as ManagerAppContext;
|
|
var url = managerAppContext.host! + "/api/Resource/" + resourceId; // TO TEST TODO UPDATE ROUTE
|
|
var test2 = await http.readBytes(Uri.parse(url));
|
|
final base64Str = base64.encode(test2);
|
|
Uint8List base64String = base64Decode(base64Str); // LOAD DATA
|
|
return base64String;
|
|
} catch (e) {
|
|
print(e);
|
|
print("IN CATCH");
|
|
return null;
|
|
}
|
|
}*/
|