title: passing generic type by Function(T) in flutter
body: <p>I'm trying to create a generic consumer widget that facilitates the ViewModel to its child. therefor I have two functions. one that has a function(T) after init of the ViewModel and the other for passing the model to its child Widget.</p>
  
  <p>in the generic class  is a child of ChangeNotifier and that works fine until I want to send the T value in the two Functions.</p>
  
  <p>then I get the following errors:</p>
  
  <blockquote>
    <p>type '(OnBoardingViewModel) => Null' is not a subtype of type
    '(ChangeNotifier) => void'</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>type '(BuildContext, OnBoardingViewModel, Widget) => Scaffold' is not
    a subtype of type
    '(BuildContext, ChangeNotifier, Widget) => Widget'</p>
  </blockquote>
  
  <p>But when i change the extends type from ChangeNotifier to OnBoardingViewModel, everything works fine.</p>
  
  <p>can someone help me and or explain why this ain't working??</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:get_it/get_it.dart';
  import 'package:provider/provider.dart';
  
  class StateFullConsumerWidget&lt;T extends ChangeNotifier&gt; extends StatefulWidget{
  
    StateFullConsumerWidget({@required this.builder,Key key,this.onPostViewModelInit,this.child}) : super(key : key);
  
    final Widget Function(BuildContext context, ChangeNotifier value, Widget child) builder;
    final Widget child;
  
    final void Function(T) onPostViewModelInit;
  
    @override
    _StateFullConsumerWidgetState&lt;T&gt; createState() =&gt; _StateFullConsumerWidgetState&lt;T&gt;();
  }
  
  class _StateFullConsumerWidgetState&lt;T extends ChangeNotifier&gt; extends State&lt;StateFullConsumerWidget&gt;{
    T _viewModel;
    @override
    void initState() {
      // assign the model once when state is initialised
      _viewModel = GetIt.instance.get&lt;T&gt;();
      widget.onPostViewModelInit(_viewModel);
  
  
      super.initState();
    }
    @override
    Widget build(BuildContext context) {
      return ChangeNotifierProvider&lt;T&gt;(
        builder: (context) =&gt; _viewModel,
        child: Consumer&lt;T&gt;(
          builder: widget.builder,
          child: widget.child,
        ),
      );
    }
  
  }
  </code></pre>
  
  <p>my widget</p>
  
  <pre><code>StateFullConsumerWidget&lt;OnBoardingViewModel&gt;(
        onPostViewModelInit: (viewModel){
          buildIntroList(viewModel);
          viewModel.maxPages = _introWidgetsList.length;
        },
        builder: (context,viewModel,child) {
          return Scaffold(
            key: widget.scaffoldKey,
            body: SafeArea(
              child: Container(),
              ),
            ),
          );
        },
      );
  </code></pre>
  
  <p>my ViewModel</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  class OnBoardingViewModel extends ChangeNotifier{
  
    OnBoardingViewModel(){
  
    }
  }
  </code></pre>