VB10 / flutter-architecture-template

Flutter Architecture Complete App
https://vb10.dev/#/
Apache License 2.0
650 stars 130 forks source link

How dispose will come in play? #38

Closed behlsoft closed 3 years ago

behlsoft commented 3 years ago

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?

behlsoft commented 3 years ago

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!

behlsoft commented 3 years ago

Hey any update?

behlsoft commented 3 years ago

Still no response?

VB10 commented 3 years ago

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;