text stringlengths 1 372 |
|---|
custom channels and codecs |
besides the above mentioned MethodChannel, |
you can also use the more basic |
BasicMessageChannel, which supports basic, |
asynchronous message passing using a custom message codec. |
you can also use the specialized BinaryCodec, |
StringCodec, and JSONMessageCodec |
classes, or create your own codec. |
you might also check out an example of a custom codec |
in the cloud_firestore plugin, |
which is able to serialize and deserialize many more |
types than the default types. |
<topic_end> |
<topic_start> |
channels and platform threading |
when invoking channels on the platform side destined for flutter, |
invoke them on the platform’s main thread. |
when invoking channels in flutter destined for the platform side, |
either invoke them from any isolate that is the root |
isolate, or that is registered as a background isolate. |
the handlers for the platform side can execute on the platform’s main thread |
or they can execute on a background thread if using a task queue. |
you can invoke the platform side handlers asynchronously |
and on any thread. |
info note |
on android, the platform’s main thread is sometimes |
called the “main thread”, but it is technically defined |
as the UI thread. annotate methods that need |
to be run on the UI thread with @uithread. |
on iOS, this thread is officially |
referred to as the main thread. |
<topic_end> |
<topic_start> |
using plugins and channels from background isolates |
plugins and channels can be used by any isolate, but that isolate has to be |
a root isolate (the one created by flutter) or registered as a background |
isolate for a root isolate. |
the following example shows how to register a background isolate in order to |
use a plugin from a background isolate. |
<topic_end> |
<topic_start> |
executing channel handlers on background threads |
in order for a channel’s platform side handler to |
execute on a background thread, you must use the |
task queue API. currently this feature is only |
supported on iOS and android. |
in java: |
in kotlin: |
in swift: |
info note |
in release 2.10, the task queue API is only available on the master channel |
for iOS. |
in Objective-C: |
info note |
in release 2.10, the task queue API is only available on the master channel |
for iOS. |
<topic_end> |
<topic_start> |
jumping to the UI thread in android |
to comply with channels’ UI thread requirement, |
you might need to jump from a background thread |
to android’s UI thread to execute a channel method. |
in android, you can accomplish this by post()ing a |
runnable to android’s UI thread looper, |
which causes the runnable to execute on the |
main thread at the next opportunity. |
in java: |
in kotlin: |
<topic_end> |
<topic_start> |
jumping to the main thread in iOS |
to comply with channel’s main thread requirement, |
you might need to jump from a background thread to |
iOS’s main thread to execute a channel method. |
you can accomplish this in iOS by executing a |
block on the main dispatch queue: |
in Objective-C: |
in swift: |
<topic_end> |
<topic_start> |
automatic platform adaptations |
info note |
as of the flutter 3.16 release, material 3 |
replaces material 2 as the default theme |
on all flutter apps that use material. |
<topic_end> |
<topic_start> |
adaptation philosophy |
in general, two cases of platform adaptiveness exist: |
this article mainly covers the automatic adaptations |
provided by flutter in case 1 on android and iOS. |
for case 2, flutter bundles the means to produce the |
appropriate effects of the platform conventions but doesn’t |
adapt automatically when app design choices are needed. |
for a discussion, see issue #8410 and the |
Material/Cupertino adaptive widget problem definition. |
for an example of an app using different information |
architecture structures on android and iOS but sharing |
the same content code, see the platform_design code samples. |
info |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.