auto_route_library
auto_route_library copied to clipboard
Allow code splitting
It would be helpful if we could split code based on routes. It would mean that first page can load drastically faster because other routes and their dependecies wouldn't be loaded yet. This would affect only web version.
Since flutter has already support for it make this happen would be easy with old generator.
Instead of this:
import 'package:auto_route/auto_route.dart' as _i1;
import 'home/view/home_page.dart' as _i3;
@override
final Map<String, _i1.PageFactory> pagesMap = {
HomeRoute.name: (routeData) {
return _i1.MaterialPageX<Object>(
routeData: routeData,
child: const _i3.HomePage(),
);
}
};
We could do this:
import 'package:auto_route/auto_route.dart' as _i1;
import 'package:flutter/material.dart' as _i2;
import 'home/view/home_page.dart' deferred as _i3; //deferred is the secret sauce
@override
final Map<String, _i1.PageFactory> pagesMap = {
HomeRoute.name: (routeData) {
return _i1.MaterialPageX<Object>(
routeData: routeData,
child: FutureBuilder(
future: _i3.loadLibrary(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return _i3.HomePage();
} else {
return _i2.Center(child: _i2.CircularProgressIndicator());
}
},
),
);
}
};
I'm not sure if this can be achieved when router is used with part of
though.
@dochan-consultis this looks interesting, have you benchmarked it? how can I measure the build time?
I've tried it on my app and it saved around 500kb. I'll do more benchmarks (also regarding build and load time) on monday.
Awesome. It works with GetX router. I don't see any reasons why it shouldn't work with others too. Cheers!!!
This comparison contains 18 pages of various complexity. Unfortunately I can't share code of this test. I've tried to create this comparison on example included in this project, but pages included in example are so simple that it resulted in bigger size when code splitting was used.
Here are test results.
Files:
Without splitting:
With splitting:
Load times:
Without splitting:
With splitting:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions
I have the problem with deferredLoading and AutoRouteWrapper - wrappedRoute() method is never called!
CustomRoute(page: HomePage, deferredLoading: true, )
class HomePage extends StatelessWidget implements AutoRouteWrapper {
@override
Widget wrappedRoute(BuildContext context) {}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions