DebugScreen: Level selector - Highlight all selected levels

When selecting 'Debug', it also selects all the levels which are more
important than it.
This commit is contained in:
Vishesh Handa
2020-05-20 00:50:44 +02:00
parent 4c56ddc4df
commit c935feaee0

View File

@ -194,11 +194,11 @@ class _DebugScreenState extends State<DebugScreen> {
title: const Text("Purchase Failed"), title: const Text("Purchase Failed"),
content: Column( content: Column(
children: <Widget>[ children: <Widget>[
FilterListTile('Error', 'e', filterLevel == 'e'), FilterListTile('Error', 'e', filterLevel),
FilterListTile('Warning', 'w', filterLevel == 'w'), FilterListTile('Warning', 'w', filterLevel),
FilterListTile('Info', 'i', filterLevel == 'i'), FilterListTile('Info', 'i', filterLevel),
FilterListTile('Debug', 'd', filterLevel == 'd'), FilterListTile('Debug', 'd', filterLevel),
FilterListTile('Verbose', 'v', filterLevel == 'v'), FilterListTile('Verbose', 'v', filterLevel),
], ],
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
), ),
@ -213,9 +213,9 @@ class _DebugScreenState extends State<DebugScreen> {
class FilterListTile extends StatelessWidget { class FilterListTile extends StatelessWidget {
final String publicLevel; final String publicLevel;
final String internalLevel; final String internalLevel;
final bool selected; final String currentLevel;
FilterListTile(this.publicLevel, this.internalLevel, this.selected); FilterListTile(this.publicLevel, this.internalLevel, this.currentLevel);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -225,14 +225,14 @@ class FilterListTile extends StatelessWidget {
onTap: () { onTap: () {
Navigator.pop(context, internalLevel); Navigator.pop(context, internalLevel);
}, },
selected: selected, selected: _isSelected(),
); );
} }
Icon _getIcon(BuildContext context) { Icon _getIcon(BuildContext context) {
var theme = Theme.of(context); var theme = Theme.of(context);
var color = theme.textTheme.headline6.color; var color = theme.textTheme.headline6.color;
if (selected) { if (_isSelected()) {
switch (theme.brightness) { switch (theme.brightness) {
case Brightness.light: case Brightness.light:
color = theme.primaryColor; color = theme.primaryColor;
@ -258,4 +258,31 @@ class FilterListTile extends StatelessWidget {
return Icon(Icons.all_inclusive, color: color); return Icon(Icons.all_inclusive, color: color);
} }
bool _isSelected() {
if (currentLevel == 'v') {
return true;
}
if (currentLevel == 'd' && internalLevel == 'v') {
return false;
}
if (currentLevel == 'i' && (internalLevel == 'v' || internalLevel == 'd')) {
return false;
}
if (currentLevel == 'w' &&
(internalLevel == 'v' ||
internalLevel == 'd' ||
internalLevel == 'i')) {
return false;
}
if (currentLevel == 'e' &&
(internalLevel == 'v' ||
internalLevel == 'd' ||
internalLevel == 'i' ||
internalLevel == 'w')) {
return false;
}
return true;
}
} }