Settings: Use Radio buttons in dialogs

Instead of highlighting the last selected option.
This commit is contained in:
Vishesh Handa
2019-10-19 12:02:13 +01:00
parent b4fd9d33f7
commit c2247c26e9

View File

@ -245,8 +245,7 @@ class FontSizeSettingsDialog extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
var sizes = <Widget>[]; var sizes = <Widget>[];
for (var fontSize in NoteFontSize.options) { for (var fontSize in NoteFontSize.options) {
var highlight = fontSize == prevSize; var tile = _constructTile(context, fontSize);
var tile = _constructTile(context, fontSize, highlight);
sizes.add(tile); sizes.add(tile);
} }
@ -260,28 +259,20 @@ class FontSizeSettingsDialog extends StatelessWidget {
); );
} }
Widget _constructTile( Widget _constructTile(BuildContext context, NoteFontSize fontSize) {
BuildContext context,
NoteFontSize fontSize,
bool highlight,
) {
var style = Theme.of(context).textTheme.body1; var style = Theme.of(context).textTheme.body1;
style = style.copyWith(fontSize: fontSize.toDouble()); style = style.copyWith(fontSize: fontSize.toDouble());
var tile = ListTile( var tile = RadioListTile<NoteFontSize>(
title: Text(fontSize.toPublicString(), style: style), title: Text(fontSize.toPublicString(), style: style),
onTap: () { value: fontSize,
Navigator.of(context).pop(fontSize); groupValue: prevSize,
onChanged: (NoteFontSize newVal) {
Navigator.of(context).pop(newVal);
}, },
); );
if (!highlight) {
return tile;
}
return Container( return tile;
color: Theme.of(context).highlightColor,
child: tile,
);
} }
} }
@ -309,10 +300,12 @@ class ListPreference extends StatelessWidget {
builder: (BuildContext context) { builder: (BuildContext context) {
var children = <Widget>[]; var children = <Widget>[];
for (var o in options) { for (var o in options) {
var tile = ListTile( var tile = RadioListTile<String>(
title: Text(o), title: Text(o),
onTap: () { value: o,
Navigator.of(context).pop(o); groupValue: currentOption,
onChanged: (String val) {
Navigator.of(context).pop(val);
}, },
); );
children.add(tile); children.add(tile);