Browse Source

feat(neon): Use user status icons

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/589/head
jld3103 1 year ago
parent
commit
254102b746
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 12
      packages/neon/neon/lib/src/theme/colors.dart
  2. 12
      packages/neon/neon/lib/src/widgets/user_avatar.dart

12
packages/neon/neon/lib/src/theme/colors.dart

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:nextcloud/nextcloud.dart';
/// [Color] constants which represent Nextcloud's /// [Color] constants which represent Nextcloud's
/// [color palette](https://docs.nextcloud.com/server/latest/developer_manual/design/foundations.html#color). /// [color palette](https://docs.nextcloud.com/server/latest/developer_manual/design/foundations.html#color).
@ -42,14 +41,3 @@ abstract final class NcColors {
/// Usually used in conjunction with [NcColors.decline]. /// Usually used in conjunction with [NcColors.decline].
static const Color accept = Colors.green; static const Color accept = Colors.green;
} }
/// [UserStatusPublic] status color mapping.
extension UserStatusTypeColors on UserStatusPublic {
/// The color for the user status.
Color? get color => switch (status) {
'online' => const Color(0xFF49B382),
'away' => const Color(0xFFF4A331),
'dnd' => const Color(0xFFED484C),
_ => null,
};
}

12
packages/neon/neon/lib/src/widgets/user_avatar.dart

@ -9,6 +9,7 @@ import 'package:neon/src/bloc/result_builder.dart';
import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.dart'; import 'package:neon/src/models/account.dart';
import 'package:neon/src/widgets/cached_image.dart'; import 'package:neon/src/widgets/cached_image.dart';
import 'package:neon/src/widgets/server_icon.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
@ -96,10 +97,9 @@ class _UserAvatarState extends State<NeonUserAvatar> {
Widget _userStatusIconBuilder(final BuildContext context, final Result<UserStatusPublic?> result) { Widget _userStatusIconBuilder(final BuildContext context, final Result<UserStatusPublic?> result) {
final hasEmoji = result.data?.icon != null; final hasEmoji = result.data?.icon != null;
final scaledSize = size / (hasEmoji ? 2 : 3); final scaledSize = size / (hasEmoji ? 2 : 2.5);
Widget? child; Widget? child;
Decoration? decoration;
if (result.isLoading) { if (result.isLoading) {
child = CircularProgressIndicator( child = CircularProgressIndicator(
strokeWidth: 1.5, strokeWidth: 1.5,
@ -119,20 +119,16 @@ class _UserAvatarState extends State<NeonUserAvatar> {
), ),
); );
} else if (result.hasData) { } else if (result.hasData) {
decoration = BoxDecoration( child = NeonServerIcon(icon: 'user-status-${result.data!.status}');
shape: BoxShape.circle,
color: result.data!.color,
);
} }
return SizedBox.square( return SizedBox.square(
dimension: size, dimension: size,
child: Align( child: Align(
alignment: Alignment.bottomRight, alignment: Alignment.bottomRight,
child: Container( child: SizedBox(
width: scaledSize, width: scaledSize,
height: scaledSize, height: scaledSize,
decoration: decoration,
child: child, child: child,
), ),
), ),

Loading…
Cancel
Save