Flutter developers, generally, run into layout issues while developing any Flutter app. Fortunately, Dart DevTool’s Flutter Inspector helps developers understand why layout issues occur and solve them. This tool helps you visualize and diagnose layout issues in widgets. The flutter inspector is presently available only on Android Studio IntelliJ IDE.
The widget inspector helps you visualize and explore the widget trees created by the Flutter framework. Widgets are the core building blocks for controls (like buttons, text, and toggles), layout (like padding, centering, rows, and columns), and more. The widget inspector helps understand existing layouts and diagnose layout issues, and this unique tool is also ideal for discovering all particulars of your app layout.
When debugging a layout issue, simply run the app in debug mode. Then, click the Flutter Inspector tab on the DevTools toolbar to open the inspector. Find here how developers at Flutter app development company access the Flutter inspector tool directly from Android Studio/IntelliJ.
Debugging layout issues visually with tools in Flutter Inspector
Table of Contents
Simply use this guide and utilize the features available in the toolbar. Note that the icon is used as the visual version of the label in case of limited space.
Select widget mode
This button lets you select different widgets from your app and inspect them individually. Then, choose any widget of the Widget Tree to view the blueprint of that Widget using the Layout Explorer tab. You can also use the Details Tree tab for checking many properties and nested widgets of the selected Widget.
Simply, enable this button to choose a widget on the device to inspect it. For more information, see Inspecting a widget.
When you make changes in your app and hot reload those changes, those changes likely will not immediately reflect in the Inspector tool. Here, you can click the Refresh Tree button to visualize the changes.
Simply, reload the current widget info.
Slow Animations and Debug Paint
The option of Slow Animation is useful for reducing animation speed between layouts.
Debug Paint is suitable for adding visual debugging hints to the rendering to display padding, borders, alignment, and spacers. Primarily, this feature shows a blueprint of the whole layout.
Invert oversized image
This tool gives you control to identify large-size images. Developers want their newly-created apps to run as fast as possible. But the performance of the app affects when images are of greater size and high resolution.
This button lets you draw baselines for different icons and texts you see on screen. It causes each RenderBox to paint a line at every text baseline.
This button enables you to show rotating colors on layers while repainting. When you activate this tool, you get a reason to create a border around the changing widgets. Interestingly, it is a tool for changing and debugging widgets. Repaint Rainbow comes to your help when there is a need to change inside the Widget.
Inspecting a widget
When you need to view nearby widgets and perceive their field values, browse the interactive widget tree. The process of locating individual UI elements in the widget tree include:
First, click the Select Widget Mode button given in the toolbar. It will help you put the app into a “widget select” mode.
Next, click any widget displayed in the app’s UI. This command will let you easily choose the Widget shown on the app’s screen and scroll the widget tree to the parallel node.
After this, toggle the Select Widget Mode button again to depart from the widget select mode.
Give special emphasis to the size and constraints fields while debugging layout issues. Note that the constraints flow down the tree, and the sizes flow back up.
Track widget creation
The functionality of the Flutter inspector depends upon app code instrumentation, and it is also vital for understanding source locations better. At this location, widgets are created. The Flutter inspector presents the widget tree with the help of the source instrumentation, like defining source code in the UI.
If you don’t do the same, you will find the tree of nodes much deeper in the widget tree. Consequently, you will not easily understand the correspondence of the runtime widget to your app’s UI.
The source instrumentation occurs default when you launch an app from an IDE. It is also vital when you think of opting in the source instrumentation. Note that you also need to run the app with the –track-widget-creation flag:
flutter run –track-widget-creation
You can also use the inspector while launching the app without the flag.