text
stringlengths 1
372
|
|---|
other resources
|
you might find the following docs useful:
|
<topic_end>
|
<topic_start>
|
debug flutter apps from code
|
this guide describes which debugging features you can enable in your code.
|
for a full list of debugging and profiling tools, check out the
|
debugging page.
|
info note
|
if you are looking for a way to use GDB to remotely debug the
|
flutter engine running within an android app process,
|
check out flutter_gdb.
|
<topic_end>
|
<topic_start>
|
add logging to your application
|
info note
|
you can view logs in DevTools’ logging view
|
or in your system console. this sections
|
shows how to set up your logging statements.
|
you have two options for logging for your application.
|
import dart:io and invoking methods on
|
stderr and stdout. for example:
|
<code_start>
|
stderr.writeln('print me');
|
<code_end>
|
if you output too much at once, then android might discard some log lines.
|
to avoid this outcome,
|
use debugPrint() from flutter’s foundation library.
|
this wrapper around print throttles the output to avoid the android kernel
|
dropping output.
|
you can also log your app using the dart:developer log() function.
|
this allows you to include greater granularity and more information
|
in the logging output.
|
<topic_end>
|
<topic_start>
|
example 1
|
<code_start>
|
import 'dart:developer' as developer;
|
void main() {
|
developer.log('log me', name: 'my.app.category');
|
developer.log('log me 1', name: 'my.other.category');
|
developer.log('log me 2', name: 'my.other.category');
|
}
|
<code_end>
|
you can also pass app data to the log call.
|
the convention for this is to use the error: named
|
parameter on the log() call, JSON encode the object
|
you want to send, and pass the encoded string to the
|
error parameter.
|
<topic_end>
|
<topic_start>
|
example 2
|
<code_start>
|
import 'dart:convert';
|
import 'dart:developer' as developer;
|
void main() {
|
var myCustomObject = MyCustomObject();
|
developer.log(
|
'log me',
|
name: 'my.app.category',
|
error: jsonEncode(myCustomObject),
|
);
|
}
|
<code_end>
|
DevTool’s logging view interprets the JSON encoded error parameter
|
as a data object.
|
DevTool renders in the details view for that log entry.
|
<topic_end>
|
<topic_start>
|
set breakpoints
|
you can set breakpoints in DevTools’ debugger or
|
in the built-in debugger of your IDE.
|
to set programmatic breakpoints:
|
insert programmatic breakpoints using the debugger() statement.
|
this statement takes an optional when argument.
|
this boolean argument sets a break when the given condition resolves to true.
|
example 3 illustrates this.
|
<topic_end>
|
<topic_start>
|
example 3
|
<code_start>
|
import 'dart:developer';
|
void someFunction(double offset) {
|
debugger(when: offset > 30);
|
// ...
|
}
|
<code_end>
|
<topic_end>
|
<topic_start>
|
debug app layers using flags
|
each layer of the flutter framework provides a function to dump its
|
current state or events to the console using the debugPrint property.
|
info note
|
all of the following examples were run as macOS native apps on
|
a MacBook pro m1. these will differ from any dumps your
|
development machine prints.
|
lightbulb tip
|
each render object in any tree includes the first five
|
hexadecimal digits of its hashCode.
|
this hash serves as a unique identifier for that render object.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.