flutter_profile/lib/src/widgets/avatar/avatar_wrapper.dart

56 lines
1.3 KiB
Dart
Raw Normal View History

2022-10-31 17:15:05 +01:00
// SPDX-FileCopyrightText: 2022 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
2022-08-26 15:31:42 +02:00
import 'package:flutter/material.dart';
2022-10-21 10:42:32 +02:00
import 'package:flutter_profile/src/models/user.dart';
import 'package:flutter_profile/src/widgets/avatar/avatar.dart';
2022-08-26 15:31:42 +02:00
2022-11-24 14:56:21 +01:00
class AvatarWrapper extends StatelessWidget {
const AvatarWrapper({
2022-10-21 10:42:32 +02:00
required this.user,
2024-02-02 11:07:55 +01:00
super.key,
2022-11-24 14:56:21 +01:00
this.showName = false,
this.padding = const EdgeInsets.only(top: 16),
this.size = 100,
this.textStyle,
this.customAvatar,
this.avatarBackgroundColor,
2024-02-02 11:07:55 +01:00
});
2022-08-26 15:31:42 +02:00
2022-10-21 10:42:32 +02:00
final User user;
2022-11-24 14:56:21 +01:00
final Widget? customAvatar;
final Color? avatarBackgroundColor;
2022-11-24 14:56:21 +01:00
final bool showName;
final EdgeInsets padding;
final TextStyle? textStyle;
final double size;
2022-08-26 15:31:42 +02:00
@override
Widget build(BuildContext context) {
2022-11-24 14:56:21 +01:00
var avatar = customAvatar ??
Avatar(
user: user,
2022-11-24 14:56:21 +01:00
size: size,
avatarBackgroundColor: avatarBackgroundColor,
);
2022-11-24 14:56:21 +01:00
return showName
? Column(
children: [
avatar,
Padding(
padding: padding,
child: Flexible(
child: Text(
style: textStyle,
user.displayName,
),
),
),
],
)
2022-11-24 14:56:21 +01:00
: avatar;
2022-08-26 15:31:42 +02:00
}
}