updated project style guidelines

This commit is contained in:
2024-04-03 19:18:17 +02:00
parent 27618f4404
commit 4c7f53e309
185 changed files with 505 additions and 873 deletions

View File

@ -39,8 +39,7 @@ class _CacheViewState extends State<CacheView> {
}
@override
Widget build(BuildContext context) {
return Scaffold(
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('Lokaler cache'),
),
@ -52,7 +51,7 @@ class _CacheViewState extends State<CacheView> {
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
Map<String, dynamic> element = snapshot.data![snapshot.data!.keys.elementAt(index)];
String filename = snapshot.data!.keys.elementAt(index).split('/').last;
var filename = snapshot.data!.keys.elementAt(index).split('/').last;
return ListTile(
leading: const Icon(Icons.text_snippet_outlined),
@ -60,13 +59,10 @@ class _CacheViewState extends State<CacheView> {
subtitle: Text("${filesize(jsonEncode(element).length * 8)}, ${Jiffy.parseFromMillisecondsSinceEpoch(element['lastupdate']).fromNow()}"),
trailing: const Icon(Icons.arrow_right),
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) {
return JsonViewer(title: filename, data: jsonDecode(element['json']));
},));
Navigator.push(context, MaterialPageRoute(builder: (context) => JsonViewer(title: filename, data: jsonDecode(element['json'])),));
},
onLongPress: () {
showDialog(context: context, builder: (context) {
return SimpleDialog(
showDialog(context: context, builder: (context) => SimpleDialog(
children: [
const ListTile(
leading: Icon(Icons.delete_forever),
@ -81,8 +77,7 @@ class _CacheViewState extends State<CacheView> {
},
)
],
);
});
));
},
);
},
@ -99,7 +94,6 @@ class _CacheViewState extends State<CacheView> {
},
),
);
}
}
extension FutureExtension<T> on Future<T> {

View File

@ -13,15 +13,12 @@ class DebugTile {
bool devConditionFulfilled() => Provider.of<SettingsProvider>(context, listen: false).val().devToolsEnabled && (onlyInDebug ? kDebugMode : true);
Widget jsonData(Map<String, dynamic> data, {bool ignoreConfig = false}) {
return callback(
Widget jsonData(Map<String, dynamic> data, {bool ignoreConfig = false}) => callback(
title: 'JSON daten anzeigen',
onTab: () => JsonViewer.asDialog(context, data)
);
}
Widget callback({String title = 'Debugaktion', required void Function() onTab}) {
return child(
Widget callback({String title = 'Debugaktion', required void Function() onTab}) => child(
ListTile(
leading: const CenteredLeading(Icon(Icons.developer_mode_outlined)),
title: Text(title),
@ -29,17 +26,14 @@ class DebugTile {
onTap: onTab,
)
);
}
Widget child(Widget child) {
return Visibility(
Widget child(Widget child) => Visibility(
visible: devConditionFulfilled(),
child: child,
);
}
void run(void Function() callback) {
if(!devConditionFulfilled()) return;
callback();
}
}
}

View File

@ -9,8 +9,7 @@ class JsonViewer extends StatelessWidget {
const JsonViewer({super.key, required this.title, required this.data});
@override
Widget build(BuildContext context) {
return Scaffold(
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(title),
),
@ -19,16 +18,11 @@ class JsonViewer extends StatelessWidget {
child: Text(format(data)),
),
);
}
static String format(Map<String, dynamic> jsonInput) {
return prettyJson(jsonInput, indent: 2);
//return jsonInput.replaceAllMapped(RegExp(r'[{,}]'), (match) => "${match.group(0)}\n ");
}
static String format(Map<String, dynamic> jsonInput) => prettyJson(jsonInput, indent: 2);
static void asDialog(BuildContext context, Map<String, dynamic> dataMap) {
showDialog(context: context, builder: (context) {
return AlertDialog(
showDialog(context: context, builder: (context) => AlertDialog(
scrollable: true,
title: const Row(children: [Icon(Icons.bug_report_outlined), Text('Rohdaten')]),
content: Text(JsonViewer.format(dataMap)),
@ -45,7 +39,6 @@ class JsonViewer extends StatelessWidget {
}, child: const Text('Inline Kopieren')),
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text('Schließen'))
],
);
});
));
}
}