Logging large strings from Flutter

前端 未结 8 1933
天涯浪人
天涯浪人 2020-12-17 07:50

I\'m trying to build a Flutter App and learning Dart in the process, but I\'m getting kind of frustrated when debugging. I have fetched a resource from an API and now I want

相关标签:
8条回答
  • 2020-12-17 08:24

    currently dart and flutter not supporting printing logs more than 1020 character (found that out by trying).

    So, I came up with this method to print long logs.

    static void LogPrint(Object object) async {
        int defaultPrintLength = 1020;
        if (object == null || object.toString().length <= defaultPrintLength) {
           print(object);
        } else {
           String log = object.toString();
           int start = 0;
           int endIndex = defaultPrintLength;
           int logLength = log.length;
           int tmpLogLength = log.length;
           while (endIndex < logLength) {
              print(log.substring(start, endIndex));
              endIndex += defaultPrintLength;
              start += defaultPrintLength;
              tmpLogLength -= defaultPrintLength;
           }
           if (tmpLogLength > 0) {
              print(log.substring(start, logLength));
           }
        }
    

    }

    hope that helped.

    0 讨论(0)
  • 2020-12-17 08:24

    There is an open issue for that: https://github.com/flutter/flutter/issues/22665

    debugPrint and print are actually truncating the output.

    0 讨论(0)
提交回复
热议问题