0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

dart/flutter で行番号付きのデバッグプリントをする

Last updated at Posted at 2025-04-17

dart で行番号付きのデバッグプリントをするパッケージ(output)を作成しました。

とりあえず、デモ用のソースを提示しておきます(dart-sdk-3.7.2 と dart-sdk-3.9.0-14.0.dev で動作を確認しました。また flutter web, flutter windows desktop でも動作しました(flutter-sdk-3.29.3))。

echo(), dump() ともに第二引数にタイトル文字列を指定すれば、
[タイトル] ==> [第一引数に指定した値]
のように表示されます。

また、dump() ではまず、スタックとレースから呼び出し関数名および呼び出し行番号をまず印字してから第一引数の値を表示します。(第二引数のタイトルが指定されていた場合は、上記のようにタイトル付きで表示されます)

pubspec..yaml
name: qiita
description: A sample command-line application
version: 0.0.1
publish_to: none

environment:
  sdk: ^3.7.2

dependencies:
  

dev_dependencies:
demo.dart
import 'package:output/output.dart';

void main() {
  final list = [11, 22, 33];
  echo(list); // (1)
  echo(list, "list"); // (2)
  dump(list); // (3)
  dump(list, "list"); // (4)
}

/*
【実行結果】
[11, 22, 33] // (1)
list ==> [11, 22, 33] // (2)
[DEBUG] @ main (file:///D:/home11/dart/qiita-output/bin/demo.dart:7:3) // (3)
[11, 22, 33] // (3)
[DEBUG] @ main (file:///D:/home11/dart/qiita-output/bin/demo.dart:8:3) // (4)
list ==> [11, 22, 33] // (4)
 */
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?