54 lines
1.4 KiB
Dart
54 lines
1.4 KiB
Dart
import 'dart:typed_data';
|
|
import 'dart:ui';
|
|
import 'package:flutter/material.dart';
|
|
import '../../../core/config/app_config.dart';
|
|
import '../../../core/utils/color_utils.dart';
|
|
|
|
class ObfuscatedAvatar extends StatelessWidget {
|
|
final Uint8List? imageBytes;
|
|
final double radius;
|
|
final Color backgroundColor;
|
|
final String? fallbackInitial;
|
|
|
|
const ObfuscatedAvatar({
|
|
Key? key,
|
|
required this.imageBytes,
|
|
this.radius = 25,
|
|
this.backgroundColor = Colors.grey,
|
|
this.fallbackInitial,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (imageBytes != null && imageBytes!.isNotEmpty) {
|
|
return ClipOval(
|
|
child: ImageFiltered(
|
|
imageFilter: AppConfig.isStealthMode
|
|
? ImageFilter.blur(sigmaX: 10, sigmaY: 10)
|
|
: ImageFilter.blur(sigmaX: 0, sigmaY: 0),
|
|
child: Image.memory(
|
|
imageBytes!,
|
|
fit: BoxFit.cover,
|
|
width: radius * 2,
|
|
height: radius * 2,
|
|
),
|
|
),
|
|
);
|
|
} else {
|
|
return CircleAvatar(
|
|
radius: radius,
|
|
backgroundColor: backgroundColor,
|
|
child: Text(
|
|
fallbackInitial != null && fallbackInitial!.isNotEmpty
|
|
? fallbackInitial![0].toUpperCase()
|
|
: '?',
|
|
style: TextStyle(
|
|
color: darken(backgroundColor),
|
|
fontSize: radius,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|