Implement showAvatars

This commit is contained in:
shilangyu 2021-04-16 20:41:33 +02:00
parent 600d52211e
commit 01e9dae0cc
3 changed files with 20 additions and 4 deletions

View File

@ -180,7 +180,10 @@ class CommunitiesTab extends HookWidget {
onTap: () => goToInstance(context,
accountsStore.loggedInInstances.elementAt(i)),
onLongPress: () => toggleCollapse(i),
leading: Avatar(url: instances[i].icon),
leading: Avatar(
url: instances[i].icon,
alwaysShow: true,
),
title: Text(
instances[i].name,
style: theme.textTheme.headline6,
@ -211,6 +214,7 @@ class CommunitiesTab extends HookWidget {
Avatar(
radius: 15,
url: comm.community.icon,
alwaysShow: true,
),
const SizedBox(width: 10),
Text(comm.community.originDisplayName),

View File

@ -257,6 +257,7 @@ class _CommunityOverview extends StatelessWidget {
child: Avatar(
url: community.community.icon,
radius: 83 / 2,
alwaysShow: true,
),
),
],

View File

@ -1,23 +1,34 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
/// User's avatar.
import '../hooks/stores.dart';
/// User's avatar. Respects the `showAvatars` setting from configStore
/// If passed url is null, a blank box is displayed to prevent weird indents
/// Can be disabled with `noBlank`
class Avatar extends StatelessWidget {
class Avatar extends HookWidget {
const Avatar({
Key? key,
required this.url,
this.radius = 25,
this.noBlank = false,
this.alwaysShow = false,
}) : super(key: key);
final String? url;
final double radius;
final bool noBlank;
/// Overrides the `showAvatars` setting
final bool alwaysShow;
@override
Widget build(BuildContext context) {
final showAvatars =
useConfigStoreSelect((configStore) => configStore.showAvatars) ||
alwaysShow;
final blankWidget = () {
if (noBlank) return const SizedBox.shrink();
@ -29,7 +40,7 @@ class Avatar extends StatelessWidget {
final imageUrl = url;
if (imageUrl == null) {
if (imageUrl == null || !showAvatars) {
return blankWidget;
}