Optimize system logs

This commit is contained in:
Hillel Coren 2021-09-22 13:10:59 +03:00
parent 4dd62ad920
commit 46ff9966ef
1 changed files with 19 additions and 10 deletions

View File

@ -28,21 +28,28 @@ class _SystemLogViewerState extends State<SystemLogViewer> {
final localization = AppLocalization.of(context); final localization = AppLocalization.of(context);
final state = StoreProvider.of<AppState>(context).state; final state = StoreProvider.of<AppState>(context).state;
var systemLogs = widget.systemLogs.where((log) {
return log.typeId != 800;
}).toList();
if (systemLogs.length > 25) {
systemLogs = systemLogs.sublist(0, 25);
}
return ScrollableListView( return ScrollableListView(
children: [ children: [
ExpansionPanelList( ExpansionPanelList(
expansionCallback: (int index, bool isExpanded) { expansionCallback: (int index, bool isExpanded) {
setState(() { setState(() {
final systemLog = widget.systemLogs[index]; final systemLog = systemLogs[index];
_isExpanded[systemLog.id] = !isExpanded; _isExpanded[systemLog.id] = !isExpanded;
}); });
}, },
children: widget.systemLogs children: systemLogs
.where((systemLog) => systemLog.isVisible) .where((systemLog) => systemLog.isVisible)
.map((systemLog) { .map((systemLog) {
final client = state.clientState.get(systemLog.clientId); final client = state.clientState.get(systemLog.clientId);
Map<String, dynamic> logs; Map<String, dynamic> logs;
if (systemLog.log.isNotEmpty) { if (_isExpanded[systemLog.id] == true && systemLog.log.isNotEmpty) {
try { try {
logs = json.decode(systemLog.log); logs = json.decode(systemLog.log);
} catch (e) { } catch (e) {
@ -76,13 +83,15 @@ class _SystemLogViewerState extends State<SystemLogViewer> {
); );
}, },
isExpanded: _isExpanded[systemLog.id] == true, isExpanded: _isExpanded[systemLog.id] == true,
body: Container( body: _isExpanded[systemLog.id] == true
color: Colors.white, ? Container(
child: Padding( color: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 8), child: Padding(
child: JsonViewer(logs ?? <String, dynamic>{}), padding: const EdgeInsets.symmetric(vertical: 8),
), child: JsonViewer(logs ?? <String, dynamic>{}),
), ),
)
: SizedBox(),
); );
}).toList(), }).toList(),
), ),