dart format
This commit is contained in:
@@ -12,35 +12,50 @@ class JsonViewer extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(title),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Text(format(data)),
|
||||
),
|
||||
);
|
||||
appBar: AppBar(title: Text(title)),
|
||||
body: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Text(format(data)),
|
||||
),
|
||||
);
|
||||
|
||||
static final _encoder = const JsonEncoder.withIndent(' ');
|
||||
|
||||
static String format(Map<String, dynamic> jsonInput) => _encoder.convert(jsonInput);
|
||||
static String format(Map<String, dynamic> jsonInput) =>
|
||||
_encoder.convert(jsonInput);
|
||||
|
||||
static void asDialog(BuildContext context, Map<String, dynamic> dataMap) {
|
||||
showDialog(context: context, builder: (dialogCtx) => AlertDialog(
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogCtx) => AlertDialog(
|
||||
scrollable: true,
|
||||
title: const Row(children: [Icon(Icons.bug_report_outlined), Text('Rohdaten')]),
|
||||
title: const Row(
|
||||
children: [Icon(Icons.bug_report_outlined), Text('Rohdaten')],
|
||||
),
|
||||
content: Text(JsonViewer.format(dataMap)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => copyToClipboard(dialogCtx, JsonViewer.format(dataMap), successMessage: 'Formatiertes JSON kopiert'),
|
||||
onPressed: () => copyToClipboard(
|
||||
dialogCtx,
|
||||
JsonViewer.format(dataMap),
|
||||
successMessage: 'Formatiertes JSON kopiert',
|
||||
),
|
||||
child: const Text('Kopieren'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => copyToClipboard(dialogCtx, dataMap.toString(), successMessage: 'Inline JSON kopiert'),
|
||||
onPressed: () => copyToClipboard(
|
||||
dialogCtx,
|
||||
dataMap.toString(),
|
||||
successMessage: 'Inline JSON kopiert',
|
||||
),
|
||||
child: const Text('Inline Kopieren'),
|
||||
),
|
||||
TextButton(onPressed: () => Navigator.of(dialogCtx).pop(), child: const Text('Schließen'))
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogCtx).pop(),
|
||||
child: const Text('Schließen'),
|
||||
),
|
||||
],
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user