Catch errors when rendering favicons
This commit is contained in:
parent
35218c2e52
commit
ca3f89c31e
26
lib/widgets/favicon.dart
Normal file
26
lib/widgets/favicon.dart
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:feet/pages/article.dart';
|
import 'package:feet/pages/article.dart';
|
||||||
|
import 'package:feet/widgets/favicon.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import '../api/api.dart';
|
import '../api/api.dart';
|
||||||
|
@ -78,11 +79,7 @@ class _HomepagePostState extends State<HomepagePost> {
|
||||||
favicon?.data != null
|
favicon?.data != null
|
||||||
? Container(
|
? Container(
|
||||||
margin: const EdgeInsets.fromLTRB(0, 0, 6, 4),
|
margin: const EdgeInsets.fromLTRB(0, 0, 6, 4),
|
||||||
child: Image.memory(
|
child: PostFavicon(favicon!.data),
|
||||||
base64Decode(favicon!.data.split(',')[1]),
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
: Container(),
|
: Container(),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|
Loading…
Reference in a new issue