reassemble method
Called whenever the application is reassembled during debugging, for example during hot reload.
This method should rerun any initialization logic that depends on global state, for example, image loading from asset bundles (since the asset bundle may have changed).
This function will only be called during development. In release builds,
the ext.flutter.reassemble
hook is not available, and so this code will
never execute.
Implementers should not rely on any ordering for hot reload source update, reassemble, and build methods after a hot reload has been initiated. It is possible that a Timer (e.g. an Animation) or a debugging session attached to the isolate could trigger a build with reloaded code before reassemble is called. Code that expects preconditions to be set by reassemble after a hot reload must be resilient to being called out of order, e.g. by fizzling instead of throwing. That said, once reassemble is called, build will be called after it at least once.
In addition to this method being invoked, it is guaranteed that the build method will be invoked when a reassemble is signaled. Most widgets therefore do not need to do anything in the reassemble method.
See also:
- Element.reassemble
- BindingBase.reassembleApplication
- Image, which uses this to reload images.
Implementation
@override
void reassemble() {
super.reassemble();
// This function is called during hot reload.
//
// Normally, if the data source changes, it would notify its listeners and
// thus trigger _handleDataSourceChanged(), which clears the row cache and
// causes the widget to rebuild.
//
// During a hot reload, though, a data source can change in ways that will
// invalidate the row cache (e.g. adding or removing columns) without ever
// triggering a notification, leaving the PaginatedDataTable in an invalid
// state. This method handles this case by clearing the cache any time the
// widget is involved in a hot reload.
_updateCaches();
}