text
stringlengths
1
372
debugging
<topic_end>
<topic_start>
what tools can i use to debug my app in flutter?
use the DevTools suite for debugging flutter or dart apps.
DevTools includes support for profiling, examining the heap,
inspecting the widget tree, logging diagnostics, debugging,
observing executed lines of code,
debugging memory leaks and memory fragmentation.
for more information, see the DevTools documentation.
<topic_end>
<topic_start>
notifications
<topic_end>
<topic_start>
how do i set up push notifications?
in android, you use firebase cloud messaging to set up
push notifications for your app.
in flutter, access this functionality using the
firebase_messaging plugin.
for more information on using the firebase cloud messaging API, see the
firebase_messaging plugin documentation.
<topic_end>
<topic_start>
introduction to declarative UI
this introduction describes the conceptual difference between the
declarative style used by flutter, and the imperative style used by
many other UI frameworks.
<topic_end>
<topic_start>
why a declarative UI?
frameworks from win32 to web to android and iOS typically use an imperative
style of UI programming. this might be the style you’re most familiar
with—where you manually construct a full-functioned UI entity,
such as a UIView or equivalent, and later mutate it using methods and
setters when the UI changes.
in order to lighten the burden on developers from having to program how to
transition between various UI states, flutter, by contrast,
lets the developer describe the current UI state and leaves the
transitioning to the framework.
this, however, requires a slight shift in thinking for how to manipulate UI.
<topic_end>
<topic_start>
how to change UI in a declarative framework
consider a simplified example below:
in the imperative style, you would typically go to ViewB’s owner
and retrieve the instance b using selectors or with findViewById or similar,
and invoke mutations on it (and implicitly invalidate it). for example:
you might also need to replicate this configuration in the constructor of
ViewB since the source of truth for the UI might outlive instance b itself.
in the declarative style, view configurations (such as flutter’s widgets)
are immutable and are only lightweight “blueprints”. to change the UI,
a widget triggers a rebuild on itself (most commonly by calling setState()
on StatefulWidgets in flutter) and constructs a new widget subtree.
<code_start>
// declarative style
return ViewB(
color: red,
child: const ViewC(),
);
<code_end>
here, rather than mutating an old instance b when the UI changes,
flutter constructs new widget instances. the framework manages many of the
responsibilities of a traditional UI object (such as maintaining the
state of the layout) behind the scenes with RenderObjects.
RenderObjects persist between frames and flutter’s lightweight widgets
tell the framework to mutate the RenderObjects between states.
the flutter framework handles the rest.
<topic_end>
<topic_start>
flutter concurrency for swift developers
both dart and swift support concurrent programming.
this guide should help you understand how
concurrency works in dart and how it compares to swift.
with this understanding, you can create
high-performing iOS apps.
when developing in the apple ecosystem,
some tasks might take a long time to complete.
these tasks include fetching or processing large amounts of data.
iOS developers typically use grand central dispatch (gcd)
to schedule tasks using a shared thread pool.
with GCD, developers add tasks to dispatch queues
and GCD decides on which thread to execute them.
but, GCD spins up threads to
handle remaining work items.
this means you can end up with a large number of threads
and the system can become over committed.
with swift, the structured concurrency model reduced the number
of threads and context switches.
now, each core has only one thread.
dart has a single-threaded execution model,
with support for isolates, an event loop, and asynchronous code.
an isolate is dart’s implementation of a lightweight thread.
unless you spawn an isolate, your dart code runs in the
main UI thread driven by an event loop.
flutter’s event loop is
equivalent to the iOS main loop—in other words,
the looper attached to the main thread.
dart’s single-threaded model doesn’t mean
you are required to run everything