Skip to content

Commit

Permalink
fix: multiple issues w/ privacy controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Turtlepaw committed Nov 14, 2024
1 parent a998fe5 commit 37f187e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 8 additions & 3 deletions lib/components/privacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class _PrivacyControlsState extends State<PrivacyControls> {
}

void _updatePrivacyControl(PrivacyControl control, bool value) {
value = !value;
if (widget.onChanged != null) {
widget.onChanged!(control, value);
}
Expand All @@ -99,17 +98,23 @@ class _PrivacyControlsState extends State<PrivacyControls> {
return SizedBox(
width: 410,
child: Card(
elevation: 0,
color: Theme.of(context).colorScheme.surfaceContainer,
clipBehavior: Clip.hardEdge,
child: ListTile(
contentPadding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
leading: Icon(icon),
title: Text(name),
subtitle: Text(description),
onTap: () => onPressed(value), // Remove ! from !value
onTap: () {
onPressed(!value);
}, // Remove ! from !value
trailing: Switch(
value: value,
onChanged: (value) => onPressed(!value),
onChanged: (value) {
onPressed(value);
},
))),
);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/components/userPreview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:flutter_advanced_avatar/flutter_advanced_avatar.dart';
import 'package:pocketbase/pocketbase.dart';
import 'package:provider/provider.dart';

String getUsernameFromUser(RecordModel user){
String getUsernameFromUser(RecordModel user, {bool? forceRandomUsername}){
final hideUsername = user.getBoolValue("hideUsernameInCommunity", false);
if(hideUsername){
if(forceRandomUsername == true || (hideUsername && forceRandomUsername == null)){
return "User ${user.id}";
} else {
return user.getStringValue("username", "User ${user.id}");
Expand All @@ -31,7 +31,7 @@ class UserPreview extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
AdvancedAvatar(
name: getUsernameFromUser(pb.authStore.model!),
name: getUsernameFromUser(pb.authStore.model!, forceRandomUsername: forceRandomUsername),
style: theme.textTheme.titleMedium
?.copyWith(color: theme.colorScheme.onPrimary),
decoration: BoxDecoration(
Expand All @@ -47,7 +47,7 @@ class UserPreview extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
trimString(getUsernameFromUser(pb.authStore.model!), 15),
trimString(getUsernameFromUser(pb.authStore.model!, forceRandomUsername: forceRandomUsername), 15),
style: theme.textTheme.headlineSmall,
textAlign: TextAlign.center,
),
Expand Down
4 changes: 4 additions & 0 deletions lib/routes/community.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ class _CommunityPageState extends State<CommunityPage> {
PrivacyControls(
onChanged: (control, value){
if(control == PrivacyControl.hideUsernameInCommunity){
print("Hide username in community changed to $value");
setState(() {
hideUsername = value;
});
setState(() {

});
}
},
),
Expand Down

0 comments on commit 37f187e

Please sign in to comment.