added logs
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:simplecloudnotifier/state/application_log.dart';
|
||||
|
||||
class DebugLogsPage extends StatefulWidget {
|
||||
@override
|
||||
@@ -6,8 +9,97 @@ class DebugLogsPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DebugLogsPageState extends State<DebugLogsPage> {
|
||||
Box<SCNLog> logBox = Hive.box<SCNLog>('scn-logs');
|
||||
|
||||
static final _dateFormat = DateFormat('yyyy-MM-dd kk:mm');
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(/* Add your UI components here */);
|
||||
return Container(
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: logBox.listenable(),
|
||||
builder: (context, Box<SCNLog> box, _) {
|
||||
return ListView.builder(
|
||||
itemCount: logBox.length,
|
||||
itemBuilder: (context, listIndex) {
|
||||
final log = logBox.getAt(logBox.length - listIndex - 1)!;
|
||||
switch (log.level) {
|
||||
case SCNLogLevel.debug:
|
||||
return buildItem(context, log, Theme.of(context).hintColor);
|
||||
case SCNLogLevel.info:
|
||||
return buildItem(context, log, Colors.blueAccent);
|
||||
case SCNLogLevel.warning:
|
||||
return buildItem(context, log, Colors.orangeAccent);
|
||||
case SCNLogLevel.error:
|
||||
return buildItem(context, log, Colors.redAccent);
|
||||
case SCNLogLevel.fatal:
|
||||
return buildItem(context, log, Colors.black);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildItem(BuildContext context, SCNLog log, Color tagColor) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 2.0),
|
||||
child: Card.filled(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(12, 1, 12, 1),
|
||||
decoration: BoxDecoration(
|
||||
color: tagColor,
|
||||
borderRadius: BorderRadius.only(topLeft: Radius.circular(8)),
|
||||
),
|
||||
child: Text(
|
||||
log.level.name.toUpperCase(),
|
||||
style: TextStyle(fontWeight: FontWeight.bold, color: Theme.of(context).cardColor, fontSize: 14),
|
||||
),
|
||||
),
|
||||
Expanded(child: SizedBox()),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 0, 8, 0),
|
||||
child: Text(_dateFormat.format(log.timestamp), style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
if (log.message.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
|
||||
child: Text(log.message, style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
if (log.additional.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
|
||||
child: SelectableText(
|
||||
log.additional,
|
||||
style: TextStyle(fontSize: 12),
|
||||
minLines: 1,
|
||||
maxLines: 10,
|
||||
),
|
||||
),
|
||||
if (log.trace.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
|
||||
child: SelectableText(
|
||||
log.trace,
|
||||
style: TextStyle(fontSize: 12),
|
||||
minLines: 1,
|
||||
maxLines: 10,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:simplecloudnotifier/pages/debug/debug_persistence_hive.dart';
|
||||
import 'package:simplecloudnotifier/pages/debug/debug_persistence_sharedprefs.dart';
|
||||
import 'package:simplecloudnotifier/state/application_log.dart';
|
||||
import 'package:simplecloudnotifier/state/request_log.dart';
|
||||
|
||||
class DebugPersistencePage extends StatefulWidget {
|
||||
@override
|
||||
@@ -6,8 +12,78 @@ class DebugPersistencePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DebugPersistencePageState extends State<DebugPersistencePage> {
|
||||
SharedPreferences? prefs = null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
SharedPreferences.getInstance().then((value) => setState(() => prefs = value));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(/* Add your UI components here */);
|
||||
return Container(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card.outlined(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute<DebugSharedPrefPage>(builder: (context) => DebugSharedPrefPage(sharedPref: prefs!)));
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(width: 30, child: Text('')),
|
||||
Expanded(child: Text('Shared Preferences', style: TextStyle(fontWeight: FontWeight.bold), textAlign: TextAlign.center)),
|
||||
SizedBox(width: 30, child: Text('${prefs?.getKeys().length.toString()}', textAlign: TextAlign.end)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Card.outlined(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute<DebugHiveBoxPage>(builder: (context) => DebugHiveBoxPage(boxName: 'scn-requests', box: Hive.box<SCNRequest>('scn-requests'))));
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(width: 30, child: Text('')),
|
||||
Expanded(child: Text('Hive [scn-requests]', style: TextStyle(fontWeight: FontWeight.bold), textAlign: TextAlign.center)),
|
||||
SizedBox(width: 30, child: Text('${Hive.box<SCNRequest>('scn-requests').length.toString()}', textAlign: TextAlign.end)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Card.outlined(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute<DebugHiveBoxPage>(builder: (context) => DebugHiveBoxPage(boxName: 'scn-requests', box: Hive.box<SCNLog>('scn-logs'))));
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(width: 30, child: Text('')),
|
||||
Expanded(child: Text('Hive [scn-logs]', style: TextStyle(fontWeight: FontWeight.bold), textAlign: TextAlign.center)),
|
||||
SizedBox(width: 30, child: Text('${Hive.box<SCNLog>('scn-logs').length.toString()}', textAlign: TextAlign.end)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
35
flutter/lib/pages/debug/debug_persistence_hive.dart
Normal file
35
flutter/lib/pages/debug/debug_persistence_hive.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:simplecloudnotifier/components/layout/scaffold.dart';
|
||||
import 'package:simplecloudnotifier/pages/debug/debug_persistence_hiveentry.dart';
|
||||
import 'package:simplecloudnotifier/state/interfaces.dart';
|
||||
|
||||
class DebugHiveBoxPage extends StatelessWidget {
|
||||
final String boxName;
|
||||
final Box<FieldDebuggable> box;
|
||||
|
||||
DebugHiveBoxPage({required this.boxName, required this.box});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SCNScaffold(
|
||||
title: 'Hive: ' + boxName,
|
||||
showSearch: false,
|
||||
showDebug: false,
|
||||
child: ListView.separated(
|
||||
itemCount: box.length,
|
||||
itemBuilder: (context, listIndex) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute<DebugHiveEntryPage>(builder: (context) => DebugHiveEntryPage(value: box.getAt(listIndex)!)));
|
||||
},
|
||||
child: ListTile(
|
||||
title: Text(box.getAt(listIndex).toString(), style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) => Divider(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
29
flutter/lib/pages/debug/debug_persistence_hiveentry.dart
Normal file
29
flutter/lib/pages/debug/debug_persistence_hiveentry.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:simplecloudnotifier/components/layout/scaffold.dart';
|
||||
import 'package:simplecloudnotifier/state/interfaces.dart';
|
||||
|
||||
class DebugHiveEntryPage extends StatelessWidget {
|
||||
final FieldDebuggable value;
|
||||
final List<(String, String)> fields;
|
||||
|
||||
DebugHiveEntryPage({required this.value}) : fields = value.debugFieldList();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SCNScaffold(
|
||||
title: 'HiveEntry',
|
||||
showSearch: false,
|
||||
showDebug: false,
|
||||
child: ListView.separated(
|
||||
itemCount: fields.length,
|
||||
itemBuilder: (context, listIndex) {
|
||||
return ListTile(
|
||||
title: Text(fields[listIndex].$1, style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
subtitle: Text(fields[listIndex].$2, style: TextStyle(fontFamily: "monospace")),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) => Divider(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
29
flutter/lib/pages/debug/debug_persistence_sharedprefs.dart
Normal file
29
flutter/lib/pages/debug/debug_persistence_sharedprefs.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:simplecloudnotifier/components/layout/scaffold.dart';
|
||||
|
||||
class DebugSharedPrefPage extends StatelessWidget {
|
||||
final SharedPreferences sharedPref;
|
||||
final List<String> keys;
|
||||
|
||||
DebugSharedPrefPage({required this.sharedPref}) : keys = sharedPref.getKeys().toList();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SCNScaffold(
|
||||
title: 'SharedPreferences',
|
||||
showSearch: false,
|
||||
showDebug: false,
|
||||
child: ListView.separated(
|
||||
itemCount: sharedPref.getKeys().length,
|
||||
itemBuilder: (context, listIndex) {
|
||||
return ListTile(
|
||||
title: Text(keys[listIndex], style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
subtitle: Text(sharedPref.get(keys[listIndex]).toString()),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) => Divider(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user