title: How to initiate ViewModel for widget(view)
body: <p>So i am writing a Flutter application that utilize the MVVM architecture. I have a viewModel for every screen(widget) with ValueNotifiers and i want to initiate the viewModel for that view.
  Now most guides suggest a Provider approach, but why provide it when i can just normally initiate it.</p>
  <p>Code:</p>
  <pre><code>class FooModel{
    final ValueNotifier&lt;bool&gt; _active = ValueNotifier&lt;bool&gt;(false);
    ValueNotifier&lt;bool&gt; get active =&gt; _active;
  
    FooModel(){_active = false;}
    doSomething(){_active=!_active}
  }
  </code></pre>
  <p>What i want to do:</p>
  <pre><code>  @override
    Widget build(BuildContext context) {
      _viewModel = FooModel();
      return Scaffold(
        body:ValueListenableBuilder&lt;bool&gt;(
            valueListenable: _viewModel.active,
            builder : (context,value,_){
              if(value)return(Text(&quot;active&quot;);
              return Text(&quot;unactive&quot;);
            }
  
        ) 
    }
  </code></pre>
  <p>what is suggested:</p>
  <pre><code>  Widget build(BuildContext context) {
      return Provider&lt;FooModel&gt;(
        create: (_) =&gt; FooModel(),
        builder: (context, child) {
          final vm = Provider.of&lt;FooModel&gt;(context);
          return ValueListenableBuilder&lt;bool&gt;(
              valueListenable: vm.active,
              builder: (context, value) {
                if (value) return Text(&quot;active&quot;);
                return Text(&quot;unactive&quot;);
              });
        },
     );
   }
  </code></pre>
  <p>Now i understand that what i suggested creates the viewModel with every build, but that should only happen when screen is loaded thanks to ValueNotifier so its fine.
  I guess i just don't understand the value of providing the viewModel.</p>