text
stringlengths 1
474
|
|---|
StreamBuilder
|
widgets are used to display the results of a Future in the UI.
|
The following example uses a FutureBuilder:
|
<code_start>class HomePage extends StatelessWidget {
|
const HomePage({super.key});
|
final HomePageViewModel viewModel = const HomePageViewModel();
|
@override
|
Widget build(BuildContext context) {
|
return CupertinoPageScaffold(
|
// Feed a FutureBuilder to your widget tree.
|
child: FutureBuilder<Weather>(
|
// Specify the Future that you want to track.
|
future: viewModel.load(),
|
builder: (context, snapshot) {
|
// A snapshot is of type `AsyncSnapshot` and contains the
|
// state of the Future. By looking if the snapshot contains
|
// an error or if the data is null, you can decide what to
|
// show to the user.
|
if (snapshot.hasData) {
|
return Center(
|
child: Text(
|
snapshot.data.toString(),
|
),
|
);
|
} else {
|
return const Center(
|
child: CupertinoActivityIndicator(),
|
);
|
}
|
},
|
),
|
);
|
}
|
}<code_end>
|
For the complete example, check out the
|
async_weather file on GitHub.<topic_end>
|
<topic_start>
|
Leveraging a background thread/isolate
|
Flutter apps can run on a variety of multi-core hardware,
|
including devices running macOS and iOS.
|
To improve the performance of these applications,
|
you must sometimes run tasks on different cores
|
concurrently. This is especially important
|
to avoid blocking UI rendering with long-running operations.In Swift, you can leverage GCD to run tasks on global queues
|
with different quality of service class (qos) properties.
|
This indicates the task’s priority.In Dart, you can offload computation to a worker isolate,
|
often called a background worker.
|
A common scenario spawns a simple worker isolate and
|
returns the results in a message when the worker exits.
|
As of Dart 2.19, you can use Isolate.run() to
|
spawn an isolate and run computations:In Flutter, you can also use the compute function
|
to spin up an isolate to run a callback function:In this case, the callback function is a top-level
|
function as shown below:You can find more information on Dart at
|
Learning Dart as a Swift developer,
|
and more information on Flutter at
|
Flutter for SwiftUI developers or
|
Flutter for UIKit developers.
|
<topic_end>
|
<topic_start>Upgrading Flutter
|
No matter which one of the Flutter release channels
|
you follow, you can use the flutter command to upgrade your
|
Flutter SDK or the packages that your app depends on.<topic_end>
|
<topic_start>
|
Upgrading the Flutter SDK
|
To update the Flutter SDK use the flutter upgrade command:This command gets the most recent version of the Flutter SDK
|
that’s available on your current Flutter channel.If you are using the stable channel
|
and want an even more recent version of the Flutter SDK,
|
switch to the beta channel using flutter channel beta,
|
and then run flutter upgrade.<topic_end>
|
<topic_start>
|
Keeping informed
|
We publish migration guides for known breaking changes.We send announcements regarding these changes to the
|
Flutter announcements mailing list.To avoid being broken by future versions of Flutter,
|
consider submitting your tests to our test registry.<topic_end>
|
<topic_start>
|
Switching Flutter channels
|
Flutter has two release channels:
|
stable and beta.<topic_end>
|
<topic_start>
|
The stable channel
|
We recommend the stable channel for new users
|
and for production app releases.
|
The team updates this channel about every three months.
|
The channel might receive occasional hot fixes
|
for high-severity or high-impact issues.The continuous integration for the Flutter team’s plugins and packages
|
includes testing against the latest stable release.The latest documentation for the stable branch
|
is at: https://api.flutter.dev<topic_end>
|
<topic_start>
|
The beta channel
|
The beta channel has the latest stable release.
|
This is the most recent version of Flutter that we have heavily tested.
|
This channel has passed all our public testing,
|
has been verified against test suites for Google products that use Flutter,
|
and has been vetted against contributed private test suites.
|
The beta channel receives regular hot fixes
|
to address newly discovered important issues.The beta channel is essentially the same as the stable channel
|
but updated monthly instead of quarterly.
|
Indeed, when the stable channel is updated,
|
it is updated to the latest beta release.<topic_end>
|
<topic_start>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.