JonasWanke / debug_overlay

🐛 View debug infos and change settings via a central overlay for your app.
https://pub.dev/packages/debug_overlay
MIT License
20 stars 5 forks source link

Can we add an option to show most recent logs first. #5

Closed saad-palapa closed 1 year ago

saad-palapa commented 1 year ago

This is what I have in a wrapper class:

import 'package:debug_overlay/debug_overlay.dart';
import 'package:flutter/widgets.dart';

class Logger {
  static final logs = LogCollection();

  static void info(String message) => _log(message, DiagnosticLevel.info);
  static void debug(String message) => _log(message, DiagnosticLevel.debug);
  static void error(String message) => _log(message, DiagnosticLevel.error);

  static void _log(String message, DiagnosticLevel level) {
    // Flutter will wait until the current build is completed before executing this code
    WidgetsBinding.instance.addPostFrameCallback((_) {
      debugPrint(message);
      logs.add(
        Log(level: level, message: message),
      );

      final reversed = logs.logs.reversed.toList();
      logs.logs.clear();
      logs.logs.addAll(reversed);
    });
  }
}

This is my hacky way to show the most recent logs first. Can we instead have that as an option?

JonasWanke commented 1 year ago

I added a toggle icon as part of v0.2.4