-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moved `ChoosePropertyPage` outside `ReorderUnitsPage` * Setup UI * Improve "Select all" UI * Implemented the logic (provider) * Implemented SelectUnits page * The hidden units are now saved * Hide units in conversion * Added translated strings * Moved `ReorderPage` to `pages` for consistency * Use `l10n` for `AppLocalizations.of(context)!`
- Loading branch information
1 parent
cd17eab
commit b8a2ca9
Showing
36 changed files
with
1,117 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:converterpro/data/default_order.dart'; | ||
import 'package:converterpro/models/settings.dart'; | ||
import 'package:converterpro/utils/utils.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class HiddenUnitsNotifier extends AsyncNotifier<Map<PROPERTYX, List>> { | ||
static final provider = | ||
AsyncNotifierProvider<HiddenUnitsNotifier, Map<PROPERTYX, List>>( | ||
HiddenUnitsNotifier.new); | ||
|
||
@override | ||
Future<Map<PROPERTYX, List>> build() async { | ||
var prefs = await ref.read(sharedPref.future); | ||
|
||
final Map<PROPERTYX, List> newState = {}; | ||
|
||
for (final property in defaultPropertiesOrder) { | ||
final storedList = prefs.getStringList(_storeKey(property)); | ||
final allUnits = defaultUnitsOrder[property]!; | ||
if (storedList == null) { | ||
newState[property] = []; // Default to no hidden units | ||
} else { | ||
final storedOrder = storedList | ||
.map( | ||
(storedString) => allUnits.firstWhereOrNull( | ||
(unit) => storedString == unit.toString(), | ||
), | ||
) | ||
.nonNulls | ||
.cast() | ||
.toList(); | ||
newState[property] = storedOrder; | ||
} | ||
} | ||
return newState; | ||
} | ||
|
||
void set(List hiddenUnits, PROPERTYX property) async { | ||
// Update the state | ||
final newState = {...state.value!}; | ||
newState[property] = hiddenUnits; | ||
state = AsyncData(newState); | ||
// Store the new values | ||
if (hiddenUnits.isEmpty) { | ||
// if there aren't hidden units (all visible), just delete the | ||
// corresponding value from storage | ||
(await ref.read(sharedPref.future)).remove(_storeKey(property)); | ||
} else { | ||
(await ref.read(sharedPref.future)).setStringList( | ||
_storeKey(property), hiddenUnits.map((e) => e.toString()).toList()); | ||
} | ||
} | ||
|
||
String _storeKey(PROPERTYX property) => | ||
'hiddenUnits_${property.toString().substring('PROPERTYX.'.length)}'; | ||
} |
Oops, something went wrong.