How dispose will come in play?
behlsoft opened this issue · 4 comments
am using baseview for my view ... init and setcontext is working fine ... how dispose will work?
i want to dispose my controllers (initialised in viewmodel) when i move to other screen.. how it is possible?
my actual condition is :- i have camera controller in my view model which i want to dispose as soon as user go back ...so where should i do that.. thanks for support!
Hey any update?
Still no response?
hello @behlsoft base view has a dispose options, and you can call your dispose custom method from viewmodel and that's fine, for example:
return BaseView(
builder: (context, value) {
return buildScaffold(value);
},
model: LoginViewModel(AuthenticationService(networkManager)),
dispose: (model) {
model.customDispose();
},
But you need some changes from base view and try to implement like this
class BaseView extends StatefulWidget {
final Widget Function(BuildContext context, T value) builder;
final T model;
final void Function(T model) onModelReady;
final void Function(T model) dispose;
final VoidCallback? onRefresh;
const BaseView(
{Key? key, required this.builder, required this.model, required this.onModelReady, this.dispose, this.onRefresh})
: super(key: key);
@OverRide
_BaseViewState createState() => _BaseViewState();
}
Now, you can able to everyting in dispose method. this method work both state and viewmodel;