fix(ui): Hide the delete button if we have only one account

This commit is contained in:
PapaTutuWawa 2024-03-30 20:18:07 +01:00
parent 8928d3a34c
commit d7927d3ca9

View File

@ -2,11 +2,10 @@ import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:moxxyv2/i18n/strings.g.dart';
import 'package:moxxyv2/ui/bloc/account.dart'; import 'package:moxxyv2/ui/bloc/account.dart';
import 'package:moxxyv2/ui/widgets/avatar.dart'; import 'package:moxxyv2/ui/widgets/avatar.dart';
import 'package:moxxyv2/i18n/strings.g.dart';
const double _accountListTileVerticalPadding = 8; const double _accountListTileVerticalPadding = 8;
const double _accountListTilePictureHeight = 58; const double _accountListTilePictureHeight = 58;
@ -15,6 +14,7 @@ class AccountListTile extends StatelessWidget {
required this.displayName, required this.displayName,
required this.jid, required this.jid,
required this.active, required this.active,
required this.showDelete,
super.key, super.key,
}); });
@ -27,6 +27,9 @@ class AccountListTile extends StatelessWidget {
/// Flag indicating whether the account is currently active. /// Flag indicating whether the account is currently active.
final bool active; final bool active;
/// Flag indicating whether to show the delete button or not.
final bool showDelete;
static double get height => static double get height =>
_accountListTileVerticalPadding * 2 + _accountListTilePictureHeight; _accountListTileVerticalPadding * 2 + _accountListTilePictureHeight;
@ -88,17 +91,18 @@ class AccountListTile extends StatelessWidget {
], ],
), ),
), ),
Padding( if (showDelete)
padding: const EdgeInsets.only(left: 24), Padding(
child: IconButton( padding: const EdgeInsets.only(left: 24),
icon: Icon( child: IconButton(
Icons.delete_outline, icon: Icon(
size: 30, Icons.delete_outline,
color: Theme.of(context).colorScheme.onSurface, size: 30,
color: Theme.of(context).colorScheme.onSurface,
),
onPressed: () {},
), ),
onPressed: () {},
), ),
),
], ],
), ),
), ),
@ -136,6 +140,7 @@ class AccountsBottomModal extends StatelessWidget {
displayName: account.displayName, displayName: account.displayName,
jid: account.jid, jid: account.jid,
active: account.jid == cubit.state.account.jid, active: account.jid == cubit.state.account.jid,
showDelete: accounts.length > 1,
), ),
) )
.toList(); .toList();