Skip to content

Commit

Permalink
Fixed bug in example app
Browse files Browse the repository at this point in the history
  • Loading branch information
JaffaKetchup committed Aug 24, 2024
1 parent c50a670 commit a77390f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class BrowseStoreStrategySelector extends StatelessWidget {
currentStrategy: resolvedCurrentStrategy,
enabled: enabled,
isUnspecifiedSelector: storeName == '(unspecified)',
isUsingUnselectedStrategy: isUsingUnselectedStrategy,
)
else
Stack(
Expand All @@ -96,8 +95,8 @@ class BrowseStoreStrategySelector extends StatelessWidget {
width: isUsingUnselectedStrategy
? switch (unspecifiedStrategy) {
InternalBrowseStoreStrategy.read => 40,
InternalBrowseStoreStrategy.readUpdate => 88,
InternalBrowseStoreStrategy.readUpdateCreate => 130,
InternalBrowseStoreStrategy.readUpdate => 85,
InternalBrowseStoreStrategy.readUpdateCreate => 128,
_ => 0,
}
: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class _BrowseStoreStrategySelectorCheckbox extends StatelessWidget {
provider.currentStores[storeName] =
InternalBrowseStoreStrategy.disable;
} else if (strategyOption ==
provider.inheritableBrowseStoreStrategy) {
provider.inheritableBrowseStoreStrategy &&
!isUnspecifiedSelector) {
// Selected same as inherited
// > Automatically enable inheritance (assumed desire, can be undone)
provider.currentStores[storeName] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ class _BrowseStoreStrategySelectorDropdown extends StatelessWidget {
required this.currentStrategy,
required this.enabled,
required this.isUnspecifiedSelector,
required this.isUsingUnselectedStrategy,
});

final String storeName;
final BrowseStoreStrategy? currentStrategy;
final bool enabled;
final bool isUnspecifiedSelector;
final bool isUsingUnselectedStrategy;

@override
Widget build(BuildContext context) => Padding(
Expand All @@ -26,30 +24,39 @@ class _BrowseStoreStrategySelectorDropdown extends StatelessWidget {
: null;

final child = switch (e) {
null => isUsingUnselectedStrategy
? switch (context
.select<GeneralProvider, InternalBrowseStoreStrategy?>(
(provider) => provider.currentStores['(unspecified)'],
)) {
InternalBrowseStoreStrategy.read => const Icon(
Icons.visibility,
color: BrowseStoreStrategySelector
._unspecifiedSelectorColor,
),
InternalBrowseStoreStrategy.readUpdate => const Icon(
Icons.edit,
color: BrowseStoreStrategySelector
._unspecifiedSelectorColor,
),
InternalBrowseStoreStrategy.readUpdateCreate =>
const Icon(
Icons.add,
color: BrowseStoreStrategySelector
._unspecifiedSelectorColor,
),
_ => const Icon(Icons.disabled_by_default_rounded),
}
: const Icon(Icons.disabled_by_default_rounded),
null when !enabled => const Icon(
Icons.disabled_by_default_rounded,
),
null when isUnspecifiedSelector => const Icon(
Icons.disabled_by_default_rounded,
color:
BrowseStoreStrategySelector._unspecifiedSelectorColor,
),
null => switch (context
.select<GeneralProvider, InternalBrowseStoreStrategy?>(
(provider) => provider.currentStores['(unspecified)'],
)) {
InternalBrowseStoreStrategy.read => const Icon(
Icons.visibility,
color: BrowseStoreStrategySelector
._unspecifiedSelectorColor,
),
InternalBrowseStoreStrategy.readUpdate => const Icon(
Icons.edit,
color: BrowseStoreStrategySelector
._unspecifiedSelectorColor,
),
InternalBrowseStoreStrategy.readUpdateCreate => const Icon(
Icons.add,
color: BrowseStoreStrategySelector
._unspecifiedSelectorColor,
),
_ => const Icon(
Icons.disabled_by_default_rounded,
color: BrowseStoreStrategySelector
._unspecifiedSelectorColor,
),
},
BrowseStoreStrategy.read =>
Icon(Icons.visibility, color: iconColor),
BrowseStoreStrategy.readUpdate =>
Expand All @@ -70,12 +77,13 @@ class _BrowseStoreStrategySelectorDropdown extends StatelessWidget {
? (BrowseStoreStrategy? v) {
final provider = context.read<GeneralProvider>();

if (v == provider.inheritableBrowseStoreStrategy) {
provider.currentStores[storeName] =
InternalBrowseStoreStrategy.inherit;
} else if (v == null) {
if (v == null) {
provider.currentStores[storeName] =
InternalBrowseStoreStrategy.disable;
} else if (v == provider.inheritableBrowseStoreStrategy &&
!isUnspecifiedSelector) {
provider.currentStores[storeName] =
InternalBrowseStoreStrategy.inherit;
} else {
provider.currentStores[storeName] =
InternalBrowseStoreStrategy.fromBrowseStoreStrategy(
Expand Down
5 changes: 4 additions & 1 deletion example/lib/src/shared/state/general_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class GeneralProvider extends ChangeNotifier {
}

final Map<String, InternalBrowseStoreStrategy> currentStores = {};
void changedCurrentStores() => notifyListeners();
void changedCurrentStores() {
print(currentStores['(unspecified)']);
notifyListeners();
}

String _urlTemplate =
sharedPrefs.getString(SharedPrefsKeys.urlTemplate.name) ??
Expand Down

0 comments on commit a77390f

Please sign in to comment.