fluffychat/lib/widgets/log_view.dart

66 lines
1.8 KiB
Dart
Raw Normal View History

2020-12-22 14:23:23 +01:00
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart';
class LogViewer extends StatefulWidget {
@override
_LogViewerState createState() => _LogViewerState();
}
class _LogViewerState extends State<LogViewer> {
Level logLevel = Level.debug;
double fontSize = 14;
@override
Widget build(BuildContext context) {
final outputEvents = Logs()
.outputEvents
.where((e) => e.level.index >= logLevel.index)
.toList();
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
title: Text(logLevel.toString()),
leading: BackButton(),
actions: [
IconButton(
icon: Icon(Icons.zoom_in_outlined),
onPressed: () => setState(() => fontSize++),
),
IconButton(
icon: Icon(Icons.zoom_out_outlined),
onPressed: () => setState(() => fontSize--),
),
PopupMenuButton<Level>(
itemBuilder: (context) => Level.values
.map((level) => PopupMenuItem(
value: level,
2021-03-04 12:28:06 +01:00
child: Text(level.toString()),
2020-12-22 14:23:23 +01:00
))
.toList(),
onSelected: (Level level) => setState(() => logLevel = level),
),
],
),
body: ListView.builder(
itemCount: outputEvents.length,
itemBuilder: (context, i) => SingleChildScrollView(
scrollDirection: Axis.horizontal,
2021-05-20 13:59:55 +02:00
child: Text(outputEvents[i].toDisplayString()),
2020-12-22 14:23:23 +01:00
),
),
);
}
}
2021-05-20 13:59:55 +02:00
extension on LogEvent {
String toDisplayString() {
var str = '# $title';
if (exception != null) {
str += ' - ${exception.toString()}';
2020-12-22 14:23:23 +01:00
}
2021-05-20 13:59:55 +02:00
if (stackTrace != null) {
str += '\n${stackTrace.toString()}';
2020-12-22 14:23:23 +01:00
}
2021-05-20 13:59:55 +02:00
return str;
2020-12-22 14:23:23 +01:00
}
}