Error: Type argument 'T' doesn't conform to the bound 'Object' of the type variable 'T' on ''. After migrating to Null Safety


I’m in the process of migrating over a large project to null safety and I’m coming across a strange error I’m not entirely sure how to fix.

"Error: Type argument ‘T’ doesn’t conform to the bound ‘Object’ of the type variable ‘T’ on ‘’."

class BaseView<T extends BaseProvider?> extends StatefulWidget {
  final Widget Function(BuildContext context, T value, Widget? child)? builder;
  final Function(T)? onModelReady;

  BaseView({this.builder, this.onModelReady});

  _BaseViewState<T> createState() => _BaseViewState<T>();

class _BaseViewState<T extends BaseProvider?> extends State<BaseView<T?>> {
  T model = locator<T>(); <---- This is throwing it

  void initState() {
    if (widget.onModelReady != null) {


  Widget build(BuildContext context) {
    return ChangeNotifierProvider<T?>(
      create: (context) => model,
      child: Consumer<T>(builder: widget.builder!),

I can’t find much info on this error and so far any method I’ve tried hasn’t worked out. Can anyone be of assistance?

I’m using Provider for state management and BaseView is what wraps all my other views during build; e.g.:

class EquipmentMainView extends StatelessWidget {
  Widget build(BuildContext context) {
    return BaseView<EquipmentProvider>(
      onModelReady: (model) async {


Posting here for anyone else that might eventually run across this in the future, just changed the nullability of BaseProvider suggested by jamesdlin by changing

class BaseView<T extends BaseProvider?>


class BaseView<T extends BaseProvider>

Answered By – Swisscheese

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *