Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug or print in Flutter web?

I'm using Flutter 1.10.15 and Android Studio 3.5.1 for Flutter Web development and my big! problem is I can't debug and even I can't print something in console because only a white page is displayed in chrome when I press "run" or "debug" button in toolbar.

The only way I can run project is in web-server mode with following command and showing variable values and exceptions in AlertDialog popup!:

flutter run -d web-server --web-hostname=192.168.50.147 --web-port=5624 --local-engine=host_debug_unopt --profile -v lib\pages\splash.dart

Can anyone tell me a solution?

like image 557
Mohsen Emami Avatar asked Nov 10 '19 06:11

Mohsen Emami


People also ask

How do I debug print in flutter?

You can use print() or debugPrint() for logging. print() may truncate some logs in android if it is too much. use debugPrint() or debugPrintThrottled() to avoid this. log also helps in dart dev tools to show formatted logging.

How do you print in flutter?

you can simply use print('whatever you want to print') same as console. log() in javascript. for more info you can check here. Save this answer.

How do you print dart logs?

import 'dart:developer'; log('data: $data'); You can also use print() , but this is not a good practice because it can slow down your program in a production environment. debugPrint , log and other methods will prevent this. Save this answer.


1 Answers

I could finally find that Google Chrome DevTools feature has a "Console" section that shows all prints written in Flutter Web's dart code when running project in Web-Server mode. This is while in Web-Server mode, non of prints are shown in Android Studio console.

like image 126
Mohsen Emami Avatar answered Sep 22 '22 22:09

Mohsen Emami