properly construct and use ListTile's in settings

+ a mockup of their functionality
master
EmaMaker 2021-09-18 21:36:24 +02:00
parent a6b5e58ab8
commit d8755bc100
2 changed files with 87 additions and 22 deletions

View File

@ -1,2 +1,3 @@
# Simple Notes
A simple note-taking app made in Flutter
A simple note-taking app made in Flutter
Notes are stored into text file format

View File

@ -33,25 +33,12 @@ class _SettingsState extends State<Settings> {
),
),
body: ListView(padding: EdgeInsets.all(8), children: [
ListTile(
isThreeLine: false,
leading: Icon(Icons.sort),
title: Text("Sort By:"),
subtitle: Text("WIP"),
),
ListTile(
leading: Icon(Icons.train),
title: Text("Theme"),
subtitle: Text("WIP"),
),
ListTile(
leading: Icon(Icons.info_outline_rounded),
title: Text("About"),
subtitle: Text("Info about this app"),
onTap: () => _aboutDialog(context),
),
_settingsEntry(new Icon(Icons.filter_alt_outlined), "Sort by",
_sortBy, _sortByDialog, context),
_settingsEntry(new Icon(Icons.brightness_medium_outlined), "Theme",
_theme, _themeDialog, context),
_settingsEntry(new Icon(Icons.info_outline), "About",
"Info about this app", _aboutDialog, context),
]),
),
onWillPop: () async {
@ -60,20 +47,97 @@ class _SettingsState extends State<Settings> {
});
}
ListTile _settingsEntry(Icon icon, String title, String? subtitle,
Function(BuildContext) f, BuildContext context) {
return ListTile(
title: Text(title),
leading: Container(
width: 25,
height: 50,
child: icon,
),
subtitle:
subtitle == null ? null : (subtitle == "" ? null : Text(subtitle)),
onTap: () => f(context),
);
}
void _toPrevious() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => MyHomePage(storage: widget.storage)));
}
String _theme = "";
String _sortBy = "";
void _sortByDialog(BuildContext context){
showDialog(
context: context,
builder: (BuildContext ctx) {
return SimpleDialog(
title: const Text('Choose theme'),
children: <Widget>[
_radioListTile("Name", "Name", _sortBy, _setSortBy),
_radioListTile("Last Modified", "Last Modified", _sortBy, _setSortBy),
],
);
});
}
void _themeDialog(BuildContext context) {
showDialog(
context: context,
builder: (BuildContext ctx) {
return SimpleDialog(
title: const Text('Choose theme'),
children: <Widget>[
_radioListTile("Follow System", "Follow System", _theme, _setTheme),
_radioListTile("Dark", "Dark", _theme, _setTheme),
_radioListTile("Light", "Light", _theme, _setTheme),
],
);
});
}
RadioListTile _radioListTile(
String title,
String value,
String groupValue,
Function(dynamic) f
) {
return new RadioListTile(
title: Text(title),
value: value,
groupValue: groupValue,
onChanged: (dynamic newValue) {
f(newValue);
});
}
void _setTheme(dynamic newTheme) {
setState(() {
_theme = newTheme;
Navigator.of(context).pop();
});
}
void _setSortBy(dynamic newTheme) {
setState(() {
_sortBy = newTheme;
Navigator.of(context).pop();
});
}
void _aboutDialog(BuildContext context) {
// debugdebugPrint("Clicked title");
showDialog(
context: context,
builder: (BuildContext ctx) {
return AboutDialog(
applicationName: "Simple Notes",
applicationLegalese: "Made with <3 by EmaMaker.\nSource Code available under GPL v3.0 on https://github.com/EmaMaker/simple_notes",
applicationLegalese:
"Made with <3 by EmaMaker.\nSource Code available under GPL v3.0 on https://github.com/EmaMaker/simple_notes",
applicationVersion: "v1.0",
);
});