Catch errors when rendering favicons

This commit is contained in:
Lea 2023-02-05 17:05:22 +01:00
parent 35218c2e52
commit ca3f89c31e
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
2 changed files with 28 additions and 5 deletions

26
lib/widgets/favicon.dart Normal file
View file

@ -0,0 +1,26 @@
import 'dart:convert';
import 'package:flutter/material.dart';
class PostFavicon extends StatelessWidget {
final String faviconData;
const PostFavicon(this.faviconData, {super.key});
@override
Widget build(BuildContext context) {
try {
return Image.memory(
base64Decode(faviconData.split(',')[1]),
width: 20,
height: 20,
errorBuilder: (context, error, stackTrace) {
print("Failed to render favicon: $error");
return Container();
},
);
} catch (e) {
print("Caught exception while trying to render favicon: $e");
return Container();
}
}
}

View file

@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:feet/pages/article.dart';
import 'package:feet/widgets/favicon.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../api/api.dart';
@ -78,11 +79,7 @@ class _HomepagePostState extends State<HomepagePost> {
favicon?.data != null
? Container(
margin: const EdgeInsets.fromLTRB(0, 0, 6, 4),
child: Image.memory(
base64Decode(favicon!.data.split(',')[1]),
width: 20,
height: 20,
),
child: PostFavicon(favicon!.data),
)
: Container(),
Expanded(