text
stringlengths 1
474
|
|---|
there are several options to avoid this exception.
|
The following solutions are listed in order of preference.<topic_end>
|
<topic_start>
|
Wrap the plugin
|
In most cases, the best approach is to wrap plugin
|
calls in your own API,
|
and provide a way of mocking your own API in tests.This has several advantages:<topic_end>
|
<topic_start>
|
Mock the plugin’s public API
|
If the plugin’s API is already based on class instances,
|
you can mock it directly, with the following caveats:<topic_end>
|
<topic_start>
|
Mock the plugin’s platform interface
|
If the plugin is a federated plugin,
|
it will include a platform interface that allows
|
registering implementations of its internal logic.
|
You can register a mock of that platform interface
|
implementation instead of the public API with the
|
following caveats:An example of when this might be necessary is
|
mocking the implementation of a plugin used by
|
a package that you rely on,
|
rather than your own code,
|
so you can’t change how it’s called.
|
However, if possible,
|
you should mock the dependency that uses the plugin instead.<topic_end>
|
<topic_start>
|
Mock the platform channel
|
If the plugin uses platform channels,
|
you can mock the platform channels using
|
TestDefaultBinaryMessenger.
|
This should only be used if, for some reason,
|
none of the methods above are available,
|
as it has several drawbacks:Because of these limitations, TestDefaultBinaryMessenger
|
is mainly useful in the internal tests
|
of plugin implementations,
|
rather than tests of code using plugins.You might also want to check out
|
Testing plugins.
|
<topic_end>
|
<topic_start>Debugging Flutter apps
|
There’s a wide variety of tools and features to help debug
|
Flutter applications. Here are some of the available tools:<topic_end>
|
<topic_start>
|
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.