i am trying to learn bloc with freezed .Everything was fine in event,state & bloc but when i am trying build with blocbuilder,this error occured while implementing for every state.

**Error is : GameapiState.dataloading isn't a type. Try correcting the name to match an existing type **

..homepage.dart


class LandingPAge extends StatelessWidget {
  const LandingPAge({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: BlocBuilder<GameapiBloc, GameapiState>(
        builder: (context, state) {
          if (state is GameapiState.dataloading()){

           context.read<GameapiBloc>().add(GameapiEvent.dataloadEvent());
          }



        },
      ),
    );
  }
}

state.dart

part of 'gameapi_bloc.dart';

@freezed
class GameapiState with _$GameapiState {
    factory GameapiState.initial() = Initial;

  const factory GameapiState.dataloading() = _Dataloading;

  const factory GameapiState.dataloaded(
      {required List<Storeclass> collections}) = _Datalaoded;

  const factory GameapiState.dataEror() = _DataError;
}

gameapi.bloc.freezed.dart

// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target

part of 'gameapi_bloc.dart';

// **************************************************************************
// FreezedGenerator
// **************************************************************************

T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
    'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');

/// @nodoc
mixin _$GameapiEvent {
  @optionalTypeArgs
  TResult when<TResult extends Object?>({
    required TResult Function() dataloadEvent,
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult? whenOrNull<TResult extends Object?>({
    TResult Function()? dataloadEvent,
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult maybeWhen<TResult extends Object?>({
    TResult Function()? dataloadEvent,
    required TResult orElse(),
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult map<TResult extends Object?>({
    required TResult Function(_DataloadEvent value) dataloadEvent,
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult? mapOrNull<TResult extends Object?>({
    TResult Function(_DataloadEvent value)? dataloadEvent,
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult maybeMap<TResult extends Object?>({
    TResult Function(_DataloadEvent value)? dataloadEvent,
    required TResult orElse(),
  }) =>
      throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $GameapiEventCopyWith<$Res> {
  factory $GameapiEventCopyWith(
          GameapiEvent value, $Res Function(GameapiEvent) then) =
      _$GameapiEventCopyWithImpl<$Res>;
}

/// @nodoc
class _$GameapiEventCopyWithImpl<$Res> implements $GameapiEventCopyWith<$Res> {
  _$GameapiEventCopyWithImpl(this._value, this._then);

  final GameapiEvent _value;
  // ignore: unused_field
  final $Res Function(GameapiEvent) _then;
}

/// @nodoc
abstract class _$$_DataloadEventCopyWith<$Res> {
  factory _$$_DataloadEventCopyWith(
          _$_DataloadEvent value, $Res Function(_$_DataloadEvent) then) =
      __$$_DataloadEventCopyWithImpl<$Res>;
}

/// @nodoc
class __$$_DataloadEventCopyWithImpl<$Res>
    extends _$GameapiEventCopyWithImpl<$Res>
    implements _$$_DataloadEventCopyWith<$Res> {
  __$$_DataloadEventCopyWithImpl(
      _$_DataloadEvent _value, $Res Function(_$_DataloadEvent) _then)
      : super(_value, (v) => _then(v as _$_DataloadEvent));

  @override
  _$_DataloadEvent get _value => super._value as _$_DataloadEvent;
}

/// @nodoc

class _$_DataloadEvent implements _DataloadEvent {
  const _$_DataloadEvent();

  @override
  String toString() {
    return 'GameapiEvent.dataloadEvent()';
  }

  @override
  bool operator ==(dynamic other) {
    return identical(this, other) ||
        (other.runtimeType == runtimeType && other is _$_DataloadEvent);
  }

  @override
  int get hashCode => runtimeType.hashCode;

  @override
  @optionalTypeArgs
  TResult when<TResult extends Object?>({
    required TResult Function() dataloadEvent,
  }) {
    return dataloadEvent();
  }

  @override
  @optionalTypeArgs
  TResult? whenOrNull<TResult extends Object?>({
    TResult Function()? dataloadEvent,
  }) {
    return dataloadEvent?.call();
  }

  @override
  @optionalTypeArgs
  TResult maybeWhen<TResult extends Object?>({
    TResult Function()? dataloadEvent,
    required TResult orElse(),
  }) {
    if (dataloadEvent != null) {
      return dataloadEvent();
    }
    return orElse();
  }

  @override
  @optionalTypeArgs
  TResult map<TResult extends Object?>({
    required TResult Function(_DataloadEvent value) dataloadEvent,
  }) {
    return dataloadEvent(this);
  }

  @override
  @optionalTypeArgs
  TResult? mapOrNull<TResult extends Object?>({
    TResult Function(_DataloadEvent value)? dataloadEvent,
  }) {
    return dataloadEvent?.call(this);
  }

  @override
  @optionalTypeArgs
  TResult maybeMap<TResult extends Object?>({
    TResult Function(_DataloadEvent value)? dataloadEvent,
    required TResult orElse(),
  }) {
    if (dataloadEvent != null) {
      return dataloadEvent(this);
    }
    return orElse();
  }
}

abstract class _DataloadEvent implements GameapiEvent {
  const factory _DataloadEvent() = _$_DataloadEvent;
}

/// @nodoc
mixin _$GameapiState {
  @optionalTypeArgs
  TResult when<TResult extends Object?>({
    required TResult Function() initial,
    required TResult Function() dataloading,
    required TResult Function(List<Storeclass> collections) dataloaded,
    required TResult Function() dataEror,
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult? whenOrNull<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult maybeWhen<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
    required TResult orElse(),
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult map<TResult extends Object?>({
    required TResult Function(Initial value) initial,
    required TResult Function(_Dataloading value) dataloading,
    required TResult Function(_Datalaoded value) dataloaded,
    required TResult Function(_DataError value) dataEror,
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult? mapOrNull<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
  }) =>
      throw _privateConstructorUsedError;
  @optionalTypeArgs
  TResult maybeMap<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
    required TResult orElse(),
  }) =>
      throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $GameapiStateCopyWith<$Res> {
  factory $GameapiStateCopyWith(
          GameapiState value, $Res Function(GameapiState) then) =
      _$GameapiStateCopyWithImpl<$Res>;
}

/// @nodoc
class _$GameapiStateCopyWithImpl<$Res> implements $GameapiStateCopyWith<$Res> {
  _$GameapiStateCopyWithImpl(this._value, this._then);

  final GameapiState _value;
  // ignore: unused_field
  final $Res Function(GameapiState) _then;
}

/// @nodoc
abstract class _$$InitialCopyWith<$Res> {
  factory _$$InitialCopyWith(_$Initial value, $Res Function(_$Initial) then) =
      __$$InitialCopyWithImpl<$Res>;
}

/// @nodoc
class __$$InitialCopyWithImpl<$Res> extends _$GameapiStateCopyWithImpl<$Res>
    implements _$$InitialCopyWith<$Res> {
  __$$InitialCopyWithImpl(_$Initial _value, $Res Function(_$Initial) _then)
      : super(_value, (v) => _then(v as _$Initial));

  @override
  _$Initial get _value => super._value as _$Initial;
}

/// @nodoc

class _$Initial implements Initial {
  _$Initial();

  @override
  String toString() {
    return 'GameapiState.initial()';
  }

  @override
  bool operator ==(dynamic other) {
    return identical(this, other) ||
        (other.runtimeType == runtimeType && other is _$Initial);
  }

  @override
  int get hashCode => runtimeType.hashCode;

  @override
  @optionalTypeArgs
  TResult when<TResult extends Object?>({
    required TResult Function() initial,
    required TResult Function() dataloading,
    required TResult Function(List<Storeclass> collections) dataloaded,
    required TResult Function() dataEror,
  }) {
    return initial();
  }

  @override
  @optionalTypeArgs
  TResult? whenOrNull<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
  }) {
    return initial?.call();
  }

  @override
  @optionalTypeArgs
  TResult maybeWhen<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
    required TResult orElse(),
  }) {
    if (initial != null) {
      return initial();
    }
    return orElse();
  }

  @override
  @optionalTypeArgs
  TResult map<TResult extends Object?>({
    required TResult Function(Initial value) initial,
    required TResult Function(_Dataloading value) dataloading,
    required TResult Function(_Datalaoded value) dataloaded,
    required TResult Function(_DataError value) dataEror,
  }) {
    return initial(this);
  }

  @override
  @optionalTypeArgs
  TResult? mapOrNull<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
  }) {
    return initial?.call(this);
  }

  @override
  @optionalTypeArgs
  TResult maybeMap<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
    required TResult orElse(),
  }) {
    if (initial != null) {
      return initial(this);
    }
    return orElse();
  }
}

abstract class Initial implements GameapiState {
  factory Initial() = _$Initial;
}

/// @nodoc
abstract class _$$_DataloadingCopyWith<$Res> {
  factory _$$_DataloadingCopyWith(
          _$_Dataloading value, $Res Function(_$_Dataloading) then) =
      __$$_DataloadingCopyWithImpl<$Res>;
}

/// @nodoc
class __$$_DataloadingCopyWithImpl<$Res>
    extends _$GameapiStateCopyWithImpl<$Res>
    implements _$$_DataloadingCopyWith<$Res> {
  __$$_DataloadingCopyWithImpl(
      _$_Dataloading _value, $Res Function(_$_Dataloading) _then)
      : super(_value, (v) => _then(v as _$_Dataloading));

  @override
  _$_Dataloading get _value => super._value as _$_Dataloading;
}

/// @nodoc

class _$_Dataloading implements _Dataloading {
  const _$_Dataloading();

  @override
  String toString() {
    return 'GameapiState.dataloading()';
  }

  @override
  bool operator ==(dynamic other) {
    return identical(this, other) ||
        (other.runtimeType == runtimeType && other is _$_Dataloading);
  }

  @override
  int get hashCode => runtimeType.hashCode;

  @override
  @optionalTypeArgs
  TResult when<TResult extends Object?>({
    required TResult Function() initial,
    required TResult Function() dataloading,
    required TResult Function(List<Storeclass> collections) dataloaded,
    required TResult Function() dataEror,
  }) {
    return dataloading();
  }

  @override
  @optionalTypeArgs
  TResult? whenOrNull<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
  }) {
    return dataloading?.call();
  }

  @override
  @optionalTypeArgs
  TResult maybeWhen<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
    required TResult orElse(),
  }) {
    if (dataloading != null) {
      return dataloading();
    }
    return orElse();
  }

  @override
  @optionalTypeArgs
  TResult map<TResult extends Object?>({
    required TResult Function(Initial value) initial,
    required TResult Function(_Dataloading value) dataloading,
    required TResult Function(_Datalaoded value) dataloaded,
    required TResult Function(_DataError value) dataEror,
  }) {
    return dataloading(this);
  }

  @override
  @optionalTypeArgs
  TResult? mapOrNull<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
  }) {
    return dataloading?.call(this);
  }

  @override
  @optionalTypeArgs
  TResult maybeMap<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
    required TResult orElse(),
  }) {
    if (dataloading != null) {
      return dataloading(this);
    }
    return orElse();
  }
}

abstract class _Dataloading implements GameapiState {
  const factory _Dataloading() = _$_Dataloading;
}

/// @nodoc
abstract class _$$_DatalaodedCopyWith<$Res> {
  factory _$$_DatalaodedCopyWith(
          _$_Datalaoded value, $Res Function(_$_Datalaoded) then) =
      __$$_DatalaodedCopyWithImpl<$Res>;
  $Res call({List<Storeclass> collections});
}

/// @nodoc
class __$$_DatalaodedCopyWithImpl<$Res> extends _$GameapiStateCopyWithImpl<$Res>
    implements _$$_DatalaodedCopyWith<$Res> {
  __$$_DatalaodedCopyWithImpl(
      _$_Datalaoded _value, $Res Function(_$_Datalaoded) _then)
      : super(_value, (v) => _then(v as _$_Datalaoded));

  @override
  _$_Datalaoded get _value => super._value as _$_Datalaoded;

  @override
  $Res call({
    Object? collections = freezed,
  }) {
    return _then(_$_Datalaoded(
      collections: collections == freezed
          ? _value._collections
          : collections // ignore: cast_nullable_to_non_nullable
              as List<Storeclass>,
    ));
  }
}

/// @nodoc

class _$_Datalaoded implements _Datalaoded {
  const _$_Datalaoded({required final List<Storeclass> collections})
      : _collections = collections;

  final List<Storeclass> _collections;
  @override
  List<Storeclass> get collections {
    // ignore: implicit_dynamic_type
    return EqualUnmodifiableListView(_collections);
  }

  @override
  String toString() {
    return 'GameapiState.dataloaded(collections: $collections)';
  }

  @override
  bool operator ==(dynamic other) {
    return identical(this, other) ||
        (other.runtimeType == runtimeType &&
            other is _$_Datalaoded &&
            const DeepCollectionEquality()
                .equals(other._collections, _collections));
  }

  @override
  int get hashCode => Object.hash(
      runtimeType, const DeepCollectionEquality().hash(_collections));

  @JsonKey(ignore: true)
  @override
  _$$_DatalaodedCopyWith<_$_Datalaoded> get copyWith =>
      __$$_DatalaodedCopyWithImpl<_$_Datalaoded>(this, _$identity);

  @override
  @optionalTypeArgs
  TResult when<TResult extends Object?>({
    required TResult Function() initial,
    required TResult Function() dataloading,
    required TResult Function(List<Storeclass> collections) dataloaded,
    required TResult Function() dataEror,
  }) {
    return dataloaded(collections);
  }

  @override
  @optionalTypeArgs
  TResult? whenOrNull<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
  }) {
    return dataloaded?.call(collections);
  }

  @override
  @optionalTypeArgs
  TResult maybeWhen<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
    required TResult orElse(),
  }) {
    if (dataloaded != null) {
      return dataloaded(collections);
    }
    return orElse();
  }

  @override
  @optionalTypeArgs
  TResult map<TResult extends Object?>({
    required TResult Function(Initial value) initial,
    required TResult Function(_Dataloading value) dataloading,
    required TResult Function(_Datalaoded value) dataloaded,
    required TResult Function(_DataError value) dataEror,
  }) {
    return dataloaded(this);
  }

  @override
  @optionalTypeArgs
  TResult? mapOrNull<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
  }) {
    return dataloaded?.call(this);
  }

  @override
  @optionalTypeArgs
  TResult maybeMap<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
    required TResult orElse(),
  }) {
    if (dataloaded != null) {
      return dataloaded(this);
    }
    return orElse();
  }
}

abstract class _Datalaoded implements GameapiState {
  const factory _Datalaoded({required final List<Storeclass> collections}) =
      _$_Datalaoded;

  List<Storeclass> get collections => throw _privateConstructorUsedError;
  @JsonKey(ignore: true)
  _$$_DatalaodedCopyWith<_$_Datalaoded> get copyWith =>
      throw _privateConstructorUsedError;
}

/// @nodoc
abstract class _$$_DataErrorCopyWith<$Res> {
  factory _$$_DataErrorCopyWith(
          _$_DataError value, $Res Function(_$_DataError) then) =
      __$$_DataErrorCopyWithImpl<$Res>;
}

/// @nodoc
class __$$_DataErrorCopyWithImpl<$Res> extends _$GameapiStateCopyWithImpl<$Res>
    implements _$$_DataErrorCopyWith<$Res> {
  __$$_DataErrorCopyWithImpl(
      _$_DataError _value, $Res Function(_$_DataError) _then)
      : super(_value, (v) => _then(v as _$_DataError));

  @override
  _$_DataError get _value => super._value as _$_DataError;
}

/// @nodoc

class _$_DataError implements _DataError {
  const _$_DataError();

  @override
  String toString() {
    return 'GameapiState.dataEror()';
  }

  @override
  bool operator ==(dynamic other) {
    return identical(this, other) ||
        (other.runtimeType == runtimeType && other is _$_DataError);
  }

  @override
  int get hashCode => runtimeType.hashCode;

  @override
  @optionalTypeArgs
  TResult when<TResult extends Object?>({
    required TResult Function() initial,
    required TResult Function() dataloading,
    required TResult Function(List<Storeclass> collections) dataloaded,
    required TResult Function() dataEror,
  }) {
    return dataEror();
  }

  @override
  @optionalTypeArgs
  TResult? whenOrNull<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
  }) {
    return dataEror?.call();
  }

  @override
  @optionalTypeArgs
  TResult maybeWhen<TResult extends Object?>({
    TResult Function()? initial,
    TResult Function()? dataloading,
    TResult Function(List<Storeclass> collections)? dataloaded,
    TResult Function()? dataEror,
    required TResult orElse(),
  }) {
    if (dataEror != null) {
      return dataEror();
    }
    return orElse();
  }

  @override
  @optionalTypeArgs
  TResult map<TResult extends Object?>({
    required TResult Function(Initial value) initial,
    required TResult Function(_Dataloading value) dataloading,
    required TResult Function(_Datalaoded value) dataloaded,
    required TResult Function(_DataError value) dataEror,
  }) {
    return dataEror(this);
  }

  @override
  @optionalTypeArgs
  TResult? mapOrNull<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
  }) {
    return dataEror?.call(this);
  }

  @override
  @optionalTypeArgs
  TResult maybeMap<TResult extends Object?>({
    TResult Function(Initial value)? initial,
    TResult Function(_Dataloading value)? dataloading,
    TResult Function(_Datalaoded value)? dataloaded,
    TResult Function(_DataError value)? dataEror,
    required TResult orElse(),
  }) {
    if (dataEror != null) {
      return dataEror(this);
    }
    return orElse();
  }
}

abstract class _DataError implements GameapiState {
  const factory _DataError() = _$_DataError;
}

1

There are 1 best solutions below

0
On

It is what it says, GameapiState.dataloading() is not a type.

Either:

  1. Make the states public by removing the underscore and give it a good name, such as const factory GameapiState.dataloading() = GameApiStateDataLoading; which you then can use as if (state is GameApiStateDataLoading)

  2. Instead of if-elsing your way through the states, use the .when() method on the state.

Number two is what I would recommend, and it would look something like this:

state.when(
  initial: () {},
  dataloading: () {},
  dataloaded: (list) {},
  dataEror: () {}, // Note the spelling mistake
)

Furthermore, you should not use context.read<T>() in the BlocBuilder as you do, it is not recommended. If you want to act on the state change, use a BlocListener instead.