skip to Main Content

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 ?

2

Answers


  1. That’s how it is supposed to work. Maybe the name got you confused, but the docs are pretty clear:

    The debugPrint function logs to console even in release mode. As per convention, calls to debugPrint should be within a debug mode check or an assert

    Login or Signup to reply.
  2. 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);
    }
     
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search