45 lines
1.6 KiB
Dart
45 lines
1.6 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatResponse.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class RichObjectStringProcessor {
|
|
static String parseTextPreview(String message, Map<String, RichObjectString>? data) {
|
|
if(data == null) return message;
|
|
|
|
data.forEach((key, value) {
|
|
message = message.replaceAll(RegExp("{$key}"), value.name);
|
|
});
|
|
|
|
return message;
|
|
}
|
|
|
|
static Future<Widget> parseAnyToWidget(String message, Map<String, RichObjectString>? data) async {
|
|
if(data == null) return Text(message);
|
|
if(!message.contains(RegExp("{file}"))) return Text(parseTextPreview(message, data));
|
|
|
|
SharedPreferences preferences = await SharedPreferences.getInstance();
|
|
|
|
Widget? back;
|
|
data.forEach((key, value) {
|
|
back = CachedNetworkImage(
|
|
errorWidget: (context, url, error) {
|
|
return Text("Datei: ${value.name}", style: const TextStyle(fontWeight: FontWeight.bold));
|
|
},
|
|
alignment: Alignment.center,
|
|
placeholder: (context, url) {
|
|
return const Padding(padding: EdgeInsets.all(10), child: CircularProgressIndicator());
|
|
},
|
|
fadeInDuration: const Duration(seconds: 1),
|
|
imageUrl: "https://cloud.marianum-fulda.de/core/preview?fileId=${value.id}&x=110&y=-1&a=1",
|
|
httpHeaders: {
|
|
"Authorization": "Basic ${base64.encode(utf8.encode("${preferences.getString("username")}:${preferences.getString("password")}"))}"
|
|
},
|
|
);
|
|
});
|
|
|
|
return back ?? Text("NOPE");
|
|
}
|
|
} |