Logging large strings from Flutter

前端 未结 8 1932
天涯浪人
天涯浪人 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:04

    How about using the Flutter log from the dart: developer library. This does not seem to be the maximum length limit like print() or debugPrint(). This is the only solution that seems to work fine. Try it as below:

    log(reallyReallyLongText)
    

    The output will be the entire long string without breaks and prefixed with [log]

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

    If you run the application in android studio it will truncate long string.

    In xcode 10.2 which i am using long string is not truncating.

    My suggestion is write print statement logs and run the application in Xcode instead of android studio.

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

    You can make your own print. Define this method

    void printWrapped(String text) {
      final pattern = RegExp('.{1,800}'); // 800 is the size of each chunk
      pattern.allMatches(text).forEach((match) => print(match.group(0)));
    }
    

    Use it like

    printWrapped("Your very long string ...");
    

    Credit

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

    Use debugPrint with the optional parameter to wrap according to the platform's output limit.

    debugPrint(someSuperLongString, wrapWidth: 1024);
    
    0 讨论(0)
  • 2020-12-17 08:16

    Use this method

    JsonEncoder encoder = new JsonEncoder.withIndent('  ');
    String prettyprint = encoder.convert(yourJsonString);
    debugPrint(prettyprint);
    

    But it works only with JSON strings, I have not idea about how to do with "normal" strings. The first thing I think is to add manually a \n after every n characters, for now, while waiting for a stable fix!

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

    Please try debugPrint('your output'); instead of print('your output'); the documentation is here if you would like to read. debugPrint throttles the output to a level to avoid being dropped by android's kernel as per the documentation.

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