Hide debug-viewers throughout the app when debug-mode is not enabled
This commit is contained in:
@ -1,20 +0,0 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class About extends StatelessWidget {
|
||||
const About({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Über diese App"),
|
||||
),
|
||||
body: const Card(
|
||||
elevation: 1,
|
||||
borderOnForeground: true,
|
||||
child: Text("Marianum Fulda"),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
|
||||
import 'dart:async';
|
||||
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 '../../../widget/errorView.dart';
|
||||
import 'jsonViewer.dart';
|
||||
|
||||
class CacheView extends StatefulWidget {
|
||||
final collection = "MarianumMobile";
|
||||
const CacheView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<CacheView> createState() => _CacheViewState();
|
||||
|
||||
Future<void> clear() async {
|
||||
await Localstore.instance.collection(collection).delete();
|
||||
}
|
||||
|
||||
Future<int> totalSize() async {
|
||||
var data = await Localstore.instance.collection(collection).get();
|
||||
if(data!.length <= 1) return jsonEncode(data.values.first).length * 8;
|
||||
return data.values.reduce((a, b) => jsonEncode(a).length + jsonEncode(b).length) * 8;
|
||||
}
|
||||
}
|
||||
|
||||
class _CacheViewState extends State<CacheView> {
|
||||
final Localstore storage = Localstore.instance;
|
||||
late Future<Map<String, dynamic>?> files;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
files = Localstore.instance.collection(widget.collection).get();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Lokaler cache"),
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: files,
|
||||
builder: (context, snapshot) {
|
||||
if(snapshot.hasData) {
|
||||
return ListView.builder(
|
||||
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;
|
||||
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.text_snippet_outlined),
|
||||
title: Text(filename),
|
||||
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']));
|
||||
},));
|
||||
},
|
||||
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: jsonEncode(element)));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if(snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator()
|
||||
);
|
||||
} else {
|
||||
return const Center(
|
||||
child: ErrorView(icon: Icons.hourglass_empty, text: "Keine Daten"),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension FutureExtension<T> on Future<T> {
|
||||
bool isCompleted() {
|
||||
final completer = Completer<T>();
|
||||
then(completer.complete).catchError(completer.completeError);
|
||||
return completer.isCompleted;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
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"))
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
@ -9,8 +9,8 @@ import '../../model/accountModel.dart';
|
||||
import '../../storage/base/settingsProvider.dart';
|
||||
import '../../theming/appTheme.dart';
|
||||
import '../../widget/confirmDialog.dart';
|
||||
import 'debug/cacheView.dart';
|
||||
import 'debug/jsonViewer.dart';
|
||||
import '../../widget/debug/cacheView.dart';
|
||||
import '../../widget/debug/jsonViewer.dart';
|
||||
|
||||
class Settings extends StatefulWidget {
|
||||
const Settings({Key? key}) : super(key: key);
|
||||
|
Reference in New Issue
Block a user