rebix
rebix

Reputation: 88

Is it safe to use print() with dart?

Is it safe to still use print() in dart (flutter 2.5.1), if not what command should I use to print errors?

  if (query != null) {
        _query.addAll(query);
      }
      return await dio.get(_url, queryParameters: _query);
    } on DioError catch (e) {
      print('DioError:$e');
    }

enter image description here

Upvotes: 0

Views: 536

Answers (2)

Afaq Ahmed
Afaq Ahmed

Reputation: 137

If you're inside a widget ,

Use debugPrint('data') , because it'll only show data in debug mode and will not run in release mode. So, it'll save you a lot of time.

Otherwise , you can also use log('data') , it'll show whole response in logging pattern in console.

Upvotes: 3

Shaan Mephobic
Shaan Mephobic

Reputation: 1216

What you are getting is just a warning. You should throw errors instead of printing it.

  if (query != null) {
        _query.addAll(query);
      }
      return await dio.get(_url, queryParameters: _query);
    } on DioError catch (e) {
      throw Exception(e);
    }

Upvotes: 3

Related Questions