Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debugPaintSizeEnabled is not working in Flutter

Tags:

flutter

I just began learning flutter and built the sample app present in Building Layout tutorial.

In the source code it's suggested to un-comment two lines, to see the visual debug lines, but so far no luck.

import 'package:flutter/material.dart';
// Uncomment lines 7 and 10 to view the visual layout at runtime.
//import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;

void main() {
  //debugPaintSizeEnabled = true;
  runApp(new MyApp());
}

What I have tried?

  1. Hot Reload
  2. Full Restart
  3. Setting other debug variables to true:
debugPaintPointersEnabled = 
    debugPaintBaselinesEnabled = 
    debugPaintLayerBordersEnabled = 
    debugRepaintRainbowEnabled = true;

, which I read from Docs. They worked fine.

My Setup?

  1. Visual Studio Code
  2. No Dart 2 Preview Mode
  3. Flutter Beta
  4. I use an Android Mobile Hardware, not Virtual (Moto G5)

Question: How to make the visual debugger work?

like image 240
Abhijit Kar ツ Avatar asked Mar 11 '18 10:03

Abhijit Kar ツ


People also ask

How do you print in flutter?

you can simply use print('whatever you want to print') same as console. log() in javascript.

How to enable debug painting in flutter?

To toggle the display of construction lines (debugPaintSizeEnabled), press "p". (this is the easiest option!) Show activity on this post. type Flutter: Toggle Debug Painting and click on it.

What does the flag debugpaintsizeenabled do?

After setting the flag debugPaintSizeEnabled to true, the app the does not display the layout grids while running the app in debug mode. After setting the flag debugPaintSizeEnabled to true, the app the does not display the layout grids while running the app in debug mode. Skip to content Sign up Why GitHub? Features → Mobile →

How to enable visual layout at runtime in flutter?

It works only on Android virtual device if you are working wih VSCode I was following the same tutorial recently to learn all about the layout elements in Flutter. To enable visual layout at runtime, what I did was quite straightforward - I added import 'package:flutter/rendering.dart' show debugPaintSizeEnabled; at the top of my main.dart file

What are the resources in the flutter portal?

The portal is full of cool resources from Flutter like Flutter Widget Guide , Flutter Projects , Code libs and etc. Flutter App Design Flutter App Development Flutter Design Flutter Development Flutter Mobile Design Flutter Mobile Development Flutter Release APK Release APK Release APK Is Not Working Release APK Is Not Working Properly


Video Answer


6 Answers

I had exactly the same problem and the only solution i found, is to toggle debug painting from VSCode command palette.

Flutter: Toggle Debug Painting

You can also make it works using the rendering library.

First you need to import it

import 'package:flutter/rendering.dart';

Then, set debugPaintSizeEnabled to true in the main method of your application or in a widget's build method

void main() {
  debugPaintSizeEnabled=true;
  runApp(MyApp());
}

You need to fully restart your application to apply effects

Here's the official documentation.

like image 196
Champe Avatar answered Oct 04 '22 19:10

Champe


Add import statements :

import 'dart:developer';

import 'package:flutter/rendering.dart';

Then in the build add the debugPaintSizeEnabled=true; like :

Widget build(BuildContext context) {
    debugPaintSizeEnabled=true;
like image 36
rahulmr Avatar answered Oct 04 '22 19:10

rahulmr


It's not necessary import anything in VSCode, just:

  1. Open command palette by Ctrl+Shift+P (Cmd for mac)
  2. Type Flutter: Toggle Debug Painting and click on it: example.
like image 24
melvinsalas Avatar answered Oct 04 '22 20:10

melvinsalas


In the terminal press 'p'

To toggle the display of construction lines (debugPaintSizeEnabled), press "p".

(this is the easiest option!)

like image 30
atreeon Avatar answered Oct 04 '22 18:10

atreeon


I think you need import 'package:flutter/rendering.dart';

like image 24
William Avatar answered Oct 04 '22 20:10

William


UPDATE

The following steps work on both android device and android virtual device if you are working with ANDROID STUDIO. It works only on Android virtual device if you are working wih VSCode

I was following the same tutorial recently to learn all about the layout elements in Flutter. To enable visual layout at runtime, what I did was quite straightforward -

  • First

I added import 'package:flutter/rendering.dart' show debugPaintSizeEnabled; at the top of my main.dart file

  • Next

I added debugPaintSizeEnabled = true; to my main() method

void main() {
  debugPaintSizeEnabled = true;
  runApp(new MyApp());
}
  • Finally

I performed a full restart of my app to reflect all the changes. It doesn't reflect changes if you perform a hot reload.

Hope this helps.

like image 25
Annsh Singh Avatar answered Oct 04 '22 18:10

Annsh Singh