text
stringlengths 1
372
|
|---|
the web creates these components as separate *.js files.
|
deferred code doesn’t impact other platforms,
|
which continue to build as normal with all deferred
|
components and assets included at initial install time.
|
though you can defer loading modules,
|
you must build the entire app and upload that app as a single
|
android app bundle (*.aab).
|
flutter doesn’t support dispatching partial updates without re-uploading
|
new android app bundles for the entire application.
|
flutter performs deferred loading when you compile your app
|
in release or profile mode.
|
debug mode treats all deferred components as regular imports.
|
the components are present at launch and load immediately.
|
this allows debug builds to hot reload.
|
for a deeper dive into the technical details of
|
how this feature works, see deferred components
|
on the flutter wiki.
|
<topic_end>
|
<topic_start>
|
how to set your project up for deferred components
|
the following instructions explain how to set up your
|
android app for deferred loading.
|
<topic_end>
|
<topic_start>
|
step 1: dependencies and initial project setup
|
add play core to the android app’s
|
build.gradle dependencies.
|
in android/app/build.gradle add the following:
|
if using the google play store as the
|
distribution model for dynamic features,
|
the app must support SplitCompat and provide an instance
|
of a PlayStoreDeferredComponentManager.
|
both of these tasks can be accomplished by setting
|
the android:name property on the application in
|
android/app/src/main/AndroidManifest.xml to
|
io.flutter.embedding.android.FlutterPlayStoreSplitApplication:
|
io.flutter.app.FlutterPlayStoreSplitApplication handles
|
both of these tasks for you. if you use
|
FlutterPlayStoreSplitApplication,
|
you can skip to step 1.3.
|
if your android application
|
is large or complex, you might want to separately support
|
SplitCompat and provide the
|
PlayStoreDynamicFeatureManager manually.
|
to support SplitCompat, there are three methods
|
(as detailed in the android docs), any of which are valid:
|
make your application class extend
|
SplitCompatApplication:
|
call SplitCompat.install(this);
|
in the attachBaseContext() method:
|
declare SplitCompatApplication as the application
|
subclass and add the flutter compatibility code from
|
FlutterApplication to your application class:
|
the embedder relies on an injected
|
DeferredComponentManager instance to handle
|
install requests for deferred components.
|
provide a PlayStoreDeferredComponentManager into
|
the flutter embedder by adding the following code
|
to your app initialization:
|
opt into deferred components by adding
|
the deferred-components entry to the app’s pubspec.yaml
|
under the flutter entry:
|
the flutter tool looks for the deferred-components
|
entry in the pubspec.yaml to determine whether the
|
app should be built as deferred or not.
|
this can be left empty for now unless you already
|
know the components desired and the dart deferred libraries
|
that go into each. you will fill in this section later
|
in step 3.3 once gen_snapshot produces the loading units.
|
<topic_end>
|
<topic_start>
|
step 2: implementing deferred dart libraries
|
next, implement deferred loaded dart libraries in your
|
app’s dart code. the implementation does not need
|
to be feature complete yet. the example in the
|
rest of this page adds a new simple deferred widget
|
as a placeholder. you can also convert existing code
|
to be deferred by modifying the imports and
|
guarding usages of deferred code behind loadLibrary()
|
futures.
|
create a new dart library.
|
for example, create a new DeferredBox widget that
|
can be downloaded at runtime.
|
this widget can be of any complexity but,
|
for the purposes of this guide,
|
create a simple box as a stand-in.
|
to create a simple blue box widget,
|
create box.dart with the following contents:
|
<code_start>
|
// box.dart
|
import 'package:flutter/material.dart';
|
/// a simple blue 30x30 box.
|
class DeferredBox extends StatelessWidget {
|
const DeferredBox({super.key});
|
@override
|
widget build(BuildContext context) {
|
return container(
|
height: 30,
|
width: 30,
|
color: colors.blue,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.