Reputation: 337
I am working on optimizing the initial page load of my Flutter web app. One path I am investigating is to reduce the binary size of main.dart.js
by splitting it into parts using deferred loading.
I am using go_router
which as far as I know doesn't support lazy loading. I have heard about auto_route
which supposedly supports such feature but it's undocumented.
Upvotes: 0
Views: 305
Reputation: 4918
in auto_route all you have to do is add deferrerdLoading: true
in the annotation, example:
@RoutePage(deferredLoading: true)
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
MyCustomFormState createState() {
return MyCustomFormState();
}
}
then run build_runner and look the generated file, it will contain the loadLibrary
stuff along with a DeferredWidget
that prints some loading while fetching the lib.
Upvotes: 0