Refactor codebase resolving warnings and remove self-package imports

This commit is contained in:
2023-06-03 11:27:14 +02:00
parent 6d0898d6ac
commit f0da6f2596
79 changed files with 204 additions and 193 deletions

View File

@ -0,0 +1,20 @@
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"),
),
);
}
}

View 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());
}
},
),
],
),
);
}
}

View 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"))
],
);
});
}
}

View File

@ -0,0 +1,192 @@
import 'package:flutter/material.dart';
import 'package:package_info/package_info.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../model/accountModel.dart';
import '../../model/appTheme.dart';
import 'debug/debugOverview.dart';
class Settings extends StatefulWidget {
const Settings({Key? key}) : super(key: key);
@override
State<Settings> createState() => _SettingsState();
}
class _SettingsState extends State<Settings> {
@override
void initState() {
super.initState();
}
bool developerMode = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Einstellungen"),
),
body: ListView(
children: [
ListTile(
leading: const Icon(Icons.logout_outlined),
title: const Text("Konto abmelden"),
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text("Abmelden?"),
content: const Text("Möchtest du dich wirklich abmelden?"),
actions: [
TextButton(
child: const Text("Abmelden"),
onPressed: () {
SharedPreferences.getInstance().then((value) => {
value.clear(),
}).then((value) => {
Provider.of<AccountModel>(context, listen: false).logout(),
Navigator.popUntil(context, (route) => !Navigator.canPop(context)),
});
}
),
TextButton(
child: const Text("Abbrechen"),
onPressed: () {
Navigator.pop(context);
},
),
],
);
},
);
},
),
const Divider(),
Consumer<AppTheme>(
builder: (context, value, child) {
return ListTile(
leading: const Icon(Icons.dark_mode_outlined),
title: const Text("Farbgebung"),
trailing: DropdownButton<ThemeMode>(
value: value.getMode,
icon: const Icon(Icons.arrow_drop_down),
items: ThemeMode.values.map((e) => DropdownMenuItem<ThemeMode>(
value: e,
enabled: e != value.getMode,
child: Row(
children: [
Icon(AppTheme.getDisplayOptions(e).icon),
const SizedBox(width: 10),
Text(AppTheme.getDisplayOptions(e).displayName),
],
),
)).toList(),
onChanged: (e) {
Provider.of<AppTheme>(context, listen: false).setTheme(e ?? ThemeMode.system);
},
),
);
},
),
const Divider(),
ListTile(
leading: const Icon(Icons.live_help_outlined),
title: const Text("Informationen und Lizenzen"),
onTap: () async {
final appInfo = await PackageInfo.fromPlatform();
if(!context.mounted) return; // TODO Fix context used in async
showAboutDialog(
context: context,
applicationIcon: const Icon(Icons.apps),
applicationName: "MarianumMobile",
applicationVersion: "${appInfo.appName}\n\nPackage: ${appInfo.packageName}\n\nVersion: ${appInfo.version}\nBuild: ${appInfo.buildNumber}",
applicationLegalese: "Dies ist ein Inoffizieller Nextcloud & Webuntis Client und wird nicht vom Marianum selbst betrieben.\n"
"Keinerlei Gewähr für Vollständigkeit, Richtigkeit und Aktualität!\n\n"
"Development build\n"
"Marianum Fulda 2023 Elias Müller",
);
},
trailing: const Icon(Icons.arrow_right),
),
ListTile(
leading: const Icon(Icons.policy_outlined),
title: const Text("Datenschutz"),
onTap: () {
launchUrl(Uri.parse("https://mhsl.eu/datenschutz.html"));
},
trailing: const Icon(Icons.open_in_new),
),
ListTile(
leading: const Icon(Icons.badge_outlined),
title: const Text("Impressum"),
onTap: () {
launchUrl(Uri.parse("https://mhsl.eu/id.html"));
},
trailing: const Icon(Icons.open_in_new),
),
const Divider(),
ListTile(
leading: const Icon(Icons.developer_mode_outlined),
title: const Text("Entwicklermodus"),
trailing: Checkbox(
visualDensity: const VisualDensity(horizontal: VisualDensity.minimumDensity),
value: developerMode,
onChanged: (state) {
setState(() {
developerMode = !developerMode;
});
},
),
),
Visibility(
visible: developerMode,
child: ListTile(
leading: const Icon(Icons.data_object),
title: const Text("Storage view"),
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) {
return const DebugOverview();
}));
},
trailing: const Icon(Icons.arrow_right),
),
),
Visibility(
visible: developerMode && false, // TODO Implement verbose logging
child: ListTile(
leading: const Icon(Icons.logo_dev),
title: const Text("Logging verbosity"),
trailing: DropdownButton<String>(
value: "1",
items: ["1", "2", "3"].map((e) => DropdownMenuItem<String>(value: e, child: Text(e))).toList(),
onChanged: (e) {
},
),
),
),
],
),
);
}
}