dart format
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:filesize/filesize.dart';
|
||||
@@ -21,9 +20,15 @@ class CacheView extends StatefulWidget {
|
||||
}
|
||||
|
||||
Future<int> totalSize() async {
|
||||
final data = await Localstore.instance.collection(RequestCache.collection).get();
|
||||
final data = await Localstore.instance
|
||||
.collection(RequestCache.collection)
|
||||
.get();
|
||||
if (data == null || data.isEmpty) return 0;
|
||||
return data.values.fold<int>(0, (sum, value) => sum + jsonEncode(value).length) * 8;
|
||||
return data.values.fold<int>(
|
||||
0,
|
||||
(sum, value) => sum + jsonEncode(value).length,
|
||||
) *
|
||||
8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,41 +44,45 @@ class _CacheViewState extends State<CacheView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Cache storage'),
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: files,
|
||||
builder: (context, snapshot) {
|
||||
if(snapshot.hasData) {
|
||||
return ListView.builder(
|
||||
itemCount: snapshot.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final key = snapshot.data!.keys.elementAt(index);
|
||||
final element = snapshot.data![key] as Map<String, dynamic>;
|
||||
final filename = key.split('/').last;
|
||||
appBar: AppBar(title: const Text('Cache storage')),
|
||||
body: FutureBuilder(
|
||||
future: files,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return ListView.builder(
|
||||
itemCount: snapshot.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final key = snapshot.data!.keys.elementAt(index);
|
||||
final element = snapshot.data![key] as Map<String, dynamic>;
|
||||
final filename = key.split('/').last;
|
||||
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.text_snippet_outlined),
|
||||
title: Text(filename),
|
||||
subtitle: Text('${filesize(jsonEncode(element).length * 8)}, ${Jiffy.parseFromMillisecondsSinceEpoch(element['lastupdate'] as int).fromNow()}'),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () => JsonViewer.asDialog(context, jsonDecode(element['json'] as String) as Map<String, dynamic>),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if(snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator()
|
||||
);
|
||||
} else {
|
||||
return const Center(
|
||||
child: PlaceholderView(icon: Icons.hourglass_empty, text: 'Keine Daten'),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.text_snippet_outlined),
|
||||
title: Text(filename),
|
||||
subtitle: Text(
|
||||
'${filesize(jsonEncode(element).length * 8)}, ${Jiffy.parseFromMillisecondsSinceEpoch(element['lastupdate'] as int).fromNow()}',
|
||||
),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () => JsonViewer.asDialog(
|
||||
context,
|
||||
jsonDecode(element['json'] as String) as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else {
|
||||
return const Center(
|
||||
child: PlaceholderView(
|
||||
icon: Icons.hourglass_empty,
|
||||
text: 'Keine Daten',
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
extension FutureExtension<T> on Future<T> {
|
||||
|
||||
@@ -12,23 +12,29 @@ class DebugTile {
|
||||
DebugTile(this.context, {this.onlyInDebug = false});
|
||||
|
||||
bool devConditionFulfilled() =>
|
||||
context.read<SettingsCubit>().val().devToolsEnabled && (onlyInDebug ? kDebugMode : true);
|
||||
context.read<SettingsCubit>().val().devToolsEnabled &&
|
||||
(onlyInDebug ? kDebugMode : true);
|
||||
|
||||
Widget jsonData(Map<String, dynamic> data, {bool ignoreConfig = false}) => 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}) => child(
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.developer_mode_outlined)),
|
||||
title: Text(title),
|
||||
subtitle: const Text('Entwicklermodus aktiviert'),
|
||||
onTap: onTab,
|
||||
),
|
||||
);
|
||||
Widget callback({
|
||||
String title = 'Debugaktion',
|
||||
required void Function() onTab,
|
||||
}) => child(
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.developer_mode_outlined)),
|
||||
title: Text(title),
|
||||
subtitle: const Text('Entwicklermodus aktiviert'),
|
||||
onTap: onTab,
|
||||
),
|
||||
);
|
||||
|
||||
Widget child(Widget child) => Visibility(visible: devConditionFulfilled(), child: child);
|
||||
Widget child(Widget child) =>
|
||||
Visibility(visible: devConditionFulfilled(), child: child);
|
||||
|
||||
void run(void Function() callback) {
|
||||
if (!devConditionFulfilled()) return;
|
||||
|
||||
@@ -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