mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-06-25 08:44:08 +00:00
print avatar warning
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
This commit is contained in:
parent
0ab6eba47d
commit
83fd99ea70
3 changed files with 35 additions and 20 deletions
|
|
@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:twonly/globals.dart';
|
||||
import 'package:twonly/locator.dart';
|
||||
import 'package:twonly/src/utils/log.dart';
|
||||
|
||||
String getAvatarSvg(Uint8List avatarSvgCompressed) {
|
||||
return utf8.decode(gzip.decode(avatarSvgCompressed));
|
||||
|
|
@ -16,28 +17,35 @@ Future<void> createPushAvatars({int? forceForUserId}) async {
|
|||
final contacts = await twonlyDB.contactsDao.getAllContacts();
|
||||
|
||||
for (final contact in contacts) {
|
||||
if (contact.avatarSvgCompressed == null) continue;
|
||||
try {
|
||||
if (contact.avatarSvgCompressed == null) continue;
|
||||
|
||||
if (forceForUserId == null) {
|
||||
if (avatarPNGFile(contact.userId).existsSync()) {
|
||||
continue; // only create the avatar in case no avatar exists yet fot this user
|
||||
if (forceForUserId == null) {
|
||||
if (avatarPNGFile(contact.userId).existsSync()) {
|
||||
continue; // only create the avatar in case no avatar exists yet fot this user
|
||||
}
|
||||
} else if (contact.userId != forceForUserId) {
|
||||
// only update the avatar for this specified contact
|
||||
continue;
|
||||
}
|
||||
} else if (contact.userId != forceForUserId) {
|
||||
// only update the avatar for this specified contact
|
||||
continue;
|
||||
|
||||
final avatarSvg = getAvatarSvg(contact.avatarSvgCompressed!);
|
||||
|
||||
final pictureInfo = await vg.loadPicture(
|
||||
SvgStringLoader(avatarSvg),
|
||||
null,
|
||||
);
|
||||
|
||||
final image = await pictureInfo.picture.toImage(270, 300);
|
||||
|
||||
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
final pngBytes = byteData!.buffer.asUint8List();
|
||||
|
||||
await avatarPNGFile(contact.userId).writeAsBytes(pngBytes);
|
||||
pictureInfo.picture.dispose();
|
||||
} catch (e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
final avatarSvg = getAvatarSvg(contact.avatarSvgCompressed!);
|
||||
|
||||
final pictureInfo = await vg.loadPicture(SvgStringLoader(avatarSvg), null);
|
||||
|
||||
final image = await pictureInfo.picture.toImage(270, 300);
|
||||
|
||||
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
final pngBytes = byteData!.buffer.asUint8List();
|
||||
|
||||
await avatarPNGFile(contact.userId).writeAsBytes(pngBytes);
|
||||
pictureInfo.picture.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:flutter_svg/svg.dart';
|
|||
import 'package:twonly/locator.dart';
|
||||
import 'package:twonly/src/database/twonly.db.dart';
|
||||
import 'package:twonly/src/utils/avatars.dart';
|
||||
import 'package:twonly/src/utils/log.dart';
|
||||
import 'package:vector_graphics/vector_graphics.dart';
|
||||
|
||||
class AvatarIcon extends StatefulWidget {
|
||||
|
|
@ -64,6 +65,12 @@ class _AvatarIconState extends State<AvatarIcon> {
|
|||
errorBuilder: errorBuilder,
|
||||
);
|
||||
}
|
||||
|
||||
Log.warn(
|
||||
'PNG avatar file for contact ${contact.userId} does not exist. Generating in background.',
|
||||
);
|
||||
unawaited(createPushAvatars(forceForUserId: contact.userId));
|
||||
|
||||
if (contact.avatarSvgCompressed != null) {
|
||||
return SvgPicture.string(
|
||||
getAvatarSvg(contact.avatarSvgCompressed!),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ description: "twonly, a privacy-friendly way to connect with friends through sec
|
|||
|
||||
publish_to: 'none'
|
||||
|
||||
version: 0.3.1+140
|
||||
version: 0.3.1+141
|
||||
|
||||
environment:
|
||||
sdk: ^3.11.0
|
||||
|
|
|
|||
Loading…
Reference in a new issue