text
stringlengths
1
474
use dart:developer Timeline utilities.Wrap the code you want to measure in Timeline methods.
<code_start>import 'dart:developer';
void main() {
Timeline.startSync('interesting function');
// iWonderHowLongThisTakes();
Timeline.finishSync();
}<code_end>
To ensure that the runtime performance characteristics closely match that
of your final product, run your app in profile mode.<topic_end>
<topic_start>
Add performance overlay
info Note
You can toggle display of the performance overlay on
your app using the Performance Overlay button in the
Flutter inspector. If you prefer to do it in code,
use the following instructions.To enable the PerformanceOverlay widget in your code,
set the showPerformanceOverlay property to true on the
MaterialApp, CupertinoApp, or WidgetsApp
constructor:<topic_end>
<topic_start>Example 10
<code_start>import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
showPerformanceOverlay: true,
title: 'My Awesome App',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const MyHomePage(title: 'My Awesome App'),
);
}
}<code_end>
(If you’re not using MaterialApp, CupertinoApp,
or WidgetsApp, you can get the same effect by wrapping your
application in a stack and putting a widget on your stack that was
created by calling PerformanceOverlay.allEnabled().)To learn how to interpret the graphs in the overlay,
check out The performance overlay in
Profiling Flutter performance.<topic_end>
<topic_start>
Add widget alignment grid
To add an overlay to a Material Design baseline grid on your app to
help verify alignments, add the debugShowMaterialGrid argument in the
MaterialApp constructor.To add an overlay to non-Material applications, add a GridPaper widget.
<topic_end>
<topic_start>Use a native language debugger
info Note
This guide presumes you understand general debugging,
have installed Flutter and git, and have familiarity
with the Dart language as well as one of the following
languages: Java, Kotlin, Swift, or Objective-C.If you write Flutter apps only with Dart code,
you can debug your code using your IDE’s debugger.
The Flutter team recommends VS Code.If you write a platform-specific plugin or
use platform-specific libraries, you can debug
that portion of your code with a native debugger.This guide shows you how you can connect two
debuggers to your Dart app, one for Dart, and one for the native code.<topic_end>
<topic_start>
Debug Dart code
This guide describes how to use VS Code to debug your Flutter app.
You can also use your preferred IDE with the
Flutter and Dart plugins installed and configured.<topic_end>
<topic_start>
Debug Dart code using VS Code
The following procedure explains how to use the Dart debugger
with the default sample Flutter app.
The featured components in VS Code work and appear when
debugging your own Flutter project as well.Create a basic Flutter app.Open the lib\main.dart file in the Flutter app using
VS Code.Click the bug icon
().
This opens the following panes in VS Code:The first time you run the debugger takes the longest.Test the debugger.a. In main.dart, click on this line:b. Press Shift + F9.
This adds a breakpoint where the
_counter variable increments.c. In the app, click the + button
to increment the counter. The app pauses.d. At this point, VS Code displays:<topic_end>
<topic_start>
VS Code Flutter debugger
The Flutter plugin for VS Code adds a number of components
to the VS Code user interface.<topic_end>
<topic_start>Changes to VS Code interface
When launched, the Flutter debugger adds debugging tools to the
VS Code interface.The following screenshot and table explain the purpose of each tool.To change where the panel (in orange) appears in VS Code,
go to View > Appearance > Panel Position.<topic_end>
<topic_start>VS Code Flutter debugging toolbar
The toolbar allows you to debug using any debugger.
You can step in, out, and over Dart statements, hot reload, or resume the app.<topic_end>
<topic_start>
Update test Flutter app
For the remainder of this guide, you need to update the
test Flutter app. This update adds native code to debug.Open the lib/main.dart file using your preferred IDE.Replace the contents of main.dart with the following code.
<code_start>// Copyright 2023 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});