mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-22 08:22:16 +03:00
Make sure OATH layout changes correctly when mixed layout is not
applicable
This commit is contained in:
parent
e45506427a
commit
e846b9c301
@ -438,8 +438,7 @@ class _FidoUnlockedPageState extends ConsumerState<_FidoUnlockedPage> {
|
||||
// between icons
|
||||
padding: const EdgeInsets.only(left: 17.0),
|
||||
child: Container(
|
||||
color:
|
||||
Theme.of(context).colorScheme.background,
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
width: 1,
|
||||
height: 45,
|
||||
),
|
||||
|
@ -48,30 +48,38 @@ final oathLayoutProvider =
|
||||
final favorites = ref.watch(favoritesProvider);
|
||||
final pinnedCreds =
|
||||
credentials.where((entry) => favorites.contains(entry.credential.id));
|
||||
return OathLayoutNotfier(
|
||||
'OATH_STATE_LAYOUT', ref.watch(prefProvider), pinnedCreds.isNotEmpty);
|
||||
return OathLayoutNotfier('OATH_STATE_LAYOUT', ref.watch(prefProvider),
|
||||
credentials, pinnedCreds.toList());
|
||||
});
|
||||
|
||||
class OathLayoutNotfier extends StateNotifier<OathLayout> {
|
||||
final String _key;
|
||||
final SharedPreferences _prefs;
|
||||
OathLayoutNotfier(this._key, this._prefs, bool _hasPinned)
|
||||
: super(_fromName(_prefs.getString(_key), _hasPinned));
|
||||
OathLayoutNotfier(this._key, this._prefs, List<OathPair> credentials,
|
||||
List<OathPair> pinnedCredentials)
|
||||
: super(
|
||||
_fromName(_prefs.getString(_key), credentials, pinnedCredentials));
|
||||
|
||||
void setLayout(OathLayout layout) {
|
||||
state = layout;
|
||||
_prefs.setString(_key, layout.name);
|
||||
}
|
||||
|
||||
static OathLayout _fromName(String? name, bool hasPinned) {
|
||||
static OathLayout _fromName(String? name, List<OathPair> credentials,
|
||||
List<OathPair> pinnedCredentials) {
|
||||
final layout = OathLayout.values.firstWhere(
|
||||
(element) => element.name == name,
|
||||
orElse: () => OathLayout.list,
|
||||
);
|
||||
// Default to list view if current key does not have
|
||||
// pinned credentials
|
||||
if (layout == OathLayout.mixed && !hasPinned) {
|
||||
return OathLayout.list;
|
||||
if (layout == OathLayout.mixed) {
|
||||
if (pinnedCredentials.isEmpty) {
|
||||
return OathLayout.list;
|
||||
}
|
||||
if (pinnedCredentials.length == credentials.length) {
|
||||
return OathLayout.grid;
|
||||
}
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
@ -402,10 +402,11 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
|
||||
final pinnedCreds = credentials
|
||||
.where((entry) => favorites.contains(entry.credential.id));
|
||||
|
||||
final availableLayouts = pinnedCreds.isNotEmpty
|
||||
final availableLayouts = pinnedCreds.isEmpty ||
|
||||
pinnedCreds.length == credentials.length
|
||||
? OathLayout.values
|
||||
: OathLayout.values
|
||||
.where((element) => element != OathLayout.mixed);
|
||||
.where((element) => element != OathLayout.mixed)
|
||||
: OathLayout.values;
|
||||
final oathLayout = ref.watch(oathLayoutProvider);
|
||||
|
||||
return Padding(
|
||||
@ -462,8 +463,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
|
||||
// between icons
|
||||
padding: const EdgeInsets.only(left: 17.0),
|
||||
child: Container(
|
||||
color:
|
||||
Theme.of(context).colorScheme.background,
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
width: 1,
|
||||
height: 45,
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user