flutterdartdebuggingapkrelease

debugPrint works in release version in flutter


in flutter when I run the app in release mode the debugPrint statements print data which I don't want to appear any ideas why this is happening ?


Solution

  • debugPrint will print values in release mode. Its purpose is not to avoid print commands in release mode.

    DebugPrint aims to avoid dropping messages on platforms that rate-limit their logging (for example, Android).

    for example, you are trying to print a huge API response but it will not print full values because there is a set limit of statement length in a simple print command. Now, using debugPrint, you can print the whole response without limit.

    Example

    print("THIS IS A VERY BIG RESPONSE...") - Output THIS IS A VE.... debugPrint("THIS IS A VERY BIG RESPONSE...") - Output THIS IS A VERY BIG RESPONSE...

    Note: In above example instead of "THIS IS A VERY BIG RESPONSE..." assume a very big value.

    for more infor please reffer to docs.

    If you want to avoide print values in production. Create a method and use it.

    void customPrint(String input)
    {
    if(kDebugMode) print(input);
    }