inject_flutter 1.2.1
inject_flutter: ^1.2.1 copied to clipboard
Flutter integration for inject_annotation. Provides ViewModelFactory and ViewModelBuilder to inject ViewModels into widgets with automatic lifecycle management, plus SubcomponentBuilder to own a @subc [...]
1.2.1 #
- add missing example
1.2.0 #
- Added
SubcomponentBuilder<T>: aStatefulWidgetthat owns the lifecycle of a@subcomponentgraph (e.g. a login session). It calls itscreatecallback (sync orasync) exactly once ininitState, exposes the result throughbuilder(context, subcomponent, child), and calls the optionaldisposecallback with the instance when removed from the tree. An asynchronouscreateshows the optionalloadingwidget while it runs and the optionalerrorbuilder (or, if none is given,FlutterError.reportError) if it fails. A widgetKeychange is the only recreation trigger — same convention asViewModelBuilder. UnlikeViewModelBuilder, the created value is not expected to be aChangeNotifier;SubcomponentBuildernever listens to it.
SubcomponentBuilder<SessionComponent>(
key: ValueKey(credentials),
create: () => sessionFactory.create(credentials),
builder: (context, session, _) => HomePage(session: session),
);
1.1.1 #
- fix dependency conflict with flutter_test
1.1.0 #
ViewModelInitializernow accepts an asynchronousinitcallback (its type widened fromvoid Function(T)toFutureOr<void> Function(T)). An asynchronousinitis awaited via aFutureBuilder, so a long-runninginitno longer races the first frame. Synchronousinitcallbacks keep working unchanged.- Added optional
loadinganderrorwidgets toViewModelFactory/ViewModelBuilder:loadingis shown while an asynchronousinitruns anderror(aViewModelErrorBuilder) when it fails. Without anerrorbuilder, an init failure is reported throughFlutterError.reportErrorinstead of being silently dropped. Both are ignored for a synchronousinit.
viewModelFactory(
init: (viewModel) => viewModel.load(), // may be sync or async
loading: const Center(child: CircularProgressIndicator()),
error: (context, error, _) => Center(child: Text('$error')),
builder: (context, viewModel, _) => /* widget */,
);
1.0.2 #
- Added support for ViewModel initialization via an optional
initcallback inViewModelFactory
@override
Widget build(BuildContext context) {
return viewModelFactory(
// Initialize the ViewModel when it's created
init: (viewModel) {
// Perfect place to trigger data loading
viewModel.loadData();
},
builder: (context, viewModel, _) {
return Scaffold(
appBar: AppBar(title: Text(viewModel.title)),
body: viewModel.isLoading
? const CircularProgressIndicator()
: ListView.builder(
itemCount: viewModel.items.length,
itemBuilder: (context, index) =>
ItemTile(item: viewModel.items[index]),
),
);
},
);
}
1.0.1 #
- inject_annotation version 1.0.0 and inject_generator version 1.0.0
- update README
1.0.0 #
- initial release