Refactor codebase resolving warnings and remove self-package imports
This commit is contained in:
106
lib/view/settings/debug/debugOverview.dart
Normal file
106
lib/view/settings/debug/debugOverview.dart
Normal file
@ -0,0 +1,106 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:filesize/filesize.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:localstore/localstore.dart';
|
||||
|
||||
import 'jsonViewer.dart';
|
||||
|
||||
class DebugOverview extends StatefulWidget {
|
||||
const DebugOverview({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<DebugOverview> createState() => _DebugOverviewState();
|
||||
}
|
||||
|
||||
class _DebugOverviewState extends State<DebugOverview> {
|
||||
|
||||
final Localstore storage = Localstore.instance;
|
||||
Future<Map<String, dynamic>?> files = Localstore.instance.collection("MarianumMobile").get();
|
||||
dynamic data;
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Lokaler cache"),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.delete_forever),
|
||||
title: const Text("Cache löschen"),
|
||||
onTap: () {
|
||||
PaintingBinding.instance.imageCache.clear();
|
||||
storage.collection("MarianumMobile").delete().then((value) => {
|
||||
Navigator.pop(context)
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
FutureBuilder(
|
||||
future: files,
|
||||
builder: (context, snapshot) {
|
||||
if(snapshot.hasData) {
|
||||
List<String> files = snapshot.data?.keys.map((e) => e.toString()).toList() ?? List<String>.empty();
|
||||
|
||||
Map<String, dynamic> getValue(int index) {
|
||||
return snapshot.data?[files[index]];
|
||||
}
|
||||
|
||||
return Expanded(
|
||||
flex: 5,
|
||||
child: ListView.builder(
|
||||
itemCount: files.length,
|
||||
itemBuilder: (context, index) {
|
||||
String filename = files[index].split("/").last;
|
||||
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.text_snippet_outlined),
|
||||
title: Text(filename),
|
||||
subtitle: Text("${filesize(getValue(index).toString().length * 8)}, ${Jiffy.parseFromMillisecondsSinceEpoch(getValue(index)['lastupdate']).fromNow()}"),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
textColor: Colors.black,
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) {
|
||||
return JsonViewer(title: filename, data: {"lastupdate": getValue(index)['lastupdate'], "json": jsonDecode(getValue(index)['json'])});
|
||||
},));
|
||||
},
|
||||
onLongPress: () {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return SimpleDialog(
|
||||
children: [
|
||||
const ListTile(
|
||||
leading: Icon(Icons.delete_forever),
|
||||
title: Text("Diese Datei löschen"),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.copy),
|
||||
title: const Text("Dateitext kopieren"),
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: getValue(index).toString()));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return snapshot.data == null ? const Text("No data") : const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
51
lib/view/settings/debug/jsonViewer.dart
Normal file
51
lib/view/settings/debug/jsonViewer.dart
Normal file
@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:pretty_json/pretty_json.dart';
|
||||
|
||||
class JsonViewer extends StatelessWidget {
|
||||
final String title;
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
const JsonViewer({Key? key, required this.title, required this.data}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(title),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
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 void asDialog(BuildContext context, Map<String, dynamic> dataMap) {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
scrollable: true,
|
||||
title: const Row(children: [Icon(Icons.bug_report_outlined), Text("Rohdaten")]),
|
||||
content: Text(JsonViewer.format(dataMap)),
|
||||
actions: [
|
||||
TextButton(onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: JsonViewer.format(dataMap))).then((value) {
|
||||
showDialog(context: context, builder: (context) => const AlertDialog(content: Text("Formatiertes JSON wurde erfolgreich in deiner Zwischenlage abgelegt.")));
|
||||
});
|
||||
}, child: const Text("Kopieren")),
|
||||
TextButton(onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: dataMap.toString())).then((value) {
|
||||
showDialog(context: context, builder: (context) => const AlertDialog(content: Text("Unformatiertes JSON wurde erfolgreich in deiner Zwischenablage abgelegt.")));
|
||||
});
|
||||
}, child: const Text("Inline Kopieren")),
|
||||
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text("Schließen"))
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user