mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 10:11:52 +03:00
Hide labels on segment buttons when they don't fit
Also adds icons, and tooltips for when labels are not show.
This commit is contained in:
parent
fd288c947b
commit
7ce2e5ccf4
@ -39,6 +39,15 @@ import '../state.dart';
|
|||||||
|
|
||||||
final _log = Logger('fido.views.reset_dialog');
|
final _log = Logger('fido.views.reset_dialog');
|
||||||
|
|
||||||
|
extension on Capability {
|
||||||
|
IconData get _icon => switch (this) {
|
||||||
|
Capability.oath => Icons.supervisor_account_outlined,
|
||||||
|
Capability.fido2 => Icons.security_outlined,
|
||||||
|
Capability.piv => Icons.approval_outlined,
|
||||||
|
_ => throw UnsupportedError('Icon not defined'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
List<Capability> getResetCapabilities(FeatureProvider hasFeature) => [
|
List<Capability> getResetCapabilities(FeatureProvider hasFeature) => [
|
||||||
if (hasFeature(features.oath)) Capability.oath,
|
if (hasFeature(features.oath)) Capability.oath,
|
||||||
if (hasFeature(features.fido)) Capability.fido2,
|
if (hasFeature(features.fido)) Capability.fido2,
|
||||||
@ -187,27 +196,32 @@ class _ResetDialogState extends ConsumerState<ResetDialog> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
if (!globalReset)
|
if (!globalReset)
|
||||||
SegmentedButton<Capability>(
|
Builder(builder: (context) {
|
||||||
emptySelectionAllowed: true,
|
final width = MediaQuery.of(context).size.width;
|
||||||
segments: getResetCapabilities(hasFeature)
|
final showLabels = width > 320;
|
||||||
.where((c) => supported & c.value != 0)
|
return SegmentedButton<Capability>(
|
||||||
.map((c) => ButtonSegment(
|
emptySelectionAllowed: true,
|
||||||
value: c,
|
segments: getResetCapabilities(hasFeature)
|
||||||
icon: const Icon(null),
|
.where((c) => supported & c.value != 0)
|
||||||
label: Padding(
|
.map((c) => ButtonSegment(
|
||||||
padding: const EdgeInsets.only(right: 22),
|
value: c,
|
||||||
child: Text(c.getDisplayName(l10n)),
|
icon: Icon(c._icon),
|
||||||
),
|
label: showLabels
|
||||||
enabled: enabled & c.value != 0,
|
? Text(c.getDisplayName(l10n))
|
||||||
))
|
: null,
|
||||||
.toList(),
|
tooltip:
|
||||||
selected: _application != null ? {_application!} : {},
|
!showLabels ? c.getDisplayName(l10n) : null,
|
||||||
onSelectionChanged: (selected) {
|
enabled: enabled & c.value != 0,
|
||||||
setState(() {
|
))
|
||||||
_application = selected.first;
|
.toList(),
|
||||||
});
|
selected: _application != null ? {_application!} : {},
|
||||||
},
|
onSelectionChanged: (selected) {
|
||||||
),
|
setState(() {
|
||||||
|
_application = selected.first;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
Text(
|
Text(
|
||||||
switch (_application) {
|
switch (_application) {
|
||||||
Capability.oath => l10n.p_warning_factory_reset,
|
Capability.oath => l10n.p_warning_factory_reset,
|
||||||
|
Loading…
Reference in New Issue
Block a user