Template
chore: 初始化脚手架 — sunny_mochi 企业级 Flutter 模板
Core 基础设施:Flavor 三包体系、Drift+SQLCipher 加密数据库 7 拦截器 Dio 网络栈、CrashReporter 崩溃日志、Sealed Failure 错误体系 5 色板主题系统、Auth 认证骨架(Clean Architecture)、Dev Panel、Mock Adapter 通过验证:flutter analyze(0 errors)、flutter test(全绿)、staging APK 74.8MB
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 用户头像,支持网络图片 + 首字母 fallback。
|
||||
class AvatarWidget extends StatelessWidget {
|
||||
const AvatarWidget({
|
||||
super.key,
|
||||
this.url,
|
||||
this.name,
|
||||
this.size = 40,
|
||||
});
|
||||
|
||||
final String? url;
|
||||
final String? name;
|
||||
final double size;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final radius = size / 2;
|
||||
|
||||
if (url != null && url!.isNotEmpty) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: url!,
|
||||
imageBuilder: (_, img) => CircleAvatar(
|
||||
radius: radius,
|
||||
backgroundImage: img,
|
||||
),
|
||||
placeholder: (_, __) => _placeholder(context),
|
||||
errorWidget: (_, __, ___) => _placeholder(context),
|
||||
);
|
||||
}
|
||||
return _placeholder(context);
|
||||
}
|
||||
|
||||
Widget _placeholder(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final initial =
|
||||
(name?.isNotEmpty == true) ? name![0].toUpperCase() : '?';
|
||||
return CircleAvatar(
|
||||
radius: size / 2,
|
||||
backgroundColor: colorScheme.primaryContainer,
|
||||
child: Text(
|
||||
initial,
|
||||
style: TextStyle(
|
||||
fontSize: size * 0.4,
|
||||
color: colorScheme.onPrimaryContainer,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user