gpt4 book ai didi

flutter - LocationList Bloc 不扩展 Bloc

转载 作者:行者123 更新时间:2023-12-03 02:42:17 26 4
gpt4 key购买 nike

我目前正在将我的代码重构为 bloc 模式,并为屏幕创建了一个 bloc,该屏幕从 Assets 中的 json 文件中获取位置列表。事件是获取,状态是初始、加载和加载。

在我的 UI 屏幕上,我想使用 BlocBuilder 但是当我使用 BlocBuilder 小部件时,它给了我错误:

LocationListBloc 不扩展 Bloc 用一行下划线的 LocationListBloc

我的代码在文件夹中的结构如下

  • lib/blocs/location_list_bloc
  • lib/blocks/location_list_event
  • lib/blocks/location_list_state
  • 库/块/块

  • 用户界面/位置列表

    location_list_state
    import 'package:flutter_bloc/flutter_bloc.dart';
    import 'package:gt_project_bloc/blocs/blocs.dart';

    class Locations extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return BlocBuilder<LocationListBloc, LocationListState>();
    }
    }
    import 'package:equatable/equatable.dart';
    import 'package:gt_project_bloc/models/models.dart';
    import 'package:meta/meta.dart';
    import 'package:equatable/equatable.dart';


    abstract class LocationListState extends Equatable {
    const LocationListState();

    @override
    List<Object> get props => [];
    }

    class LocationListinitial extends LocationListState {}

    class LocationListLoading extends LocationListState {}

    class LocationListLoaded extends LocationListState {
    final List<SavedStations> locationlist;

    LocationListLoaded(this.locationlist) : assert(locationlist != null);
    }



    location_list_event

    import 'package:equatable/equatable.dart';

    abstract class LocationListEvent extends Equatable {
    @override
    List<Object> get props => [];
    }

    class Fetch extends LocationListEvent {}

    location_list_state

    import 'package:equatable/equatable.dart';
    import 'package:gt_project_bloc/models/models.dart';
    import 'package:meta/meta.dart';
    import 'package:equatable/equatable.dart';


    abstract class LocationListState extends Equatable {
    const LocationListState();

    @override
    List<Object> get props => [];
    }

    class LocationListinitial extends LocationListState {}

    class LocationListLoading extends LocationListState {}

    class LocationListLoaded extends LocationListState {
    final List<SavedStations> locationlist;

    LocationListLoaded(this.locationlist) : assert(locationlist != null);
    }


    最佳答案

    我发现了我的问题,我在同一页面上有一个名为 LocationList 的有状态小部件,它混淆了它的状态 LocationListState 与我的 blocs 状态的相同名称

    关于flutter - LocationList Bloc 不扩展 Bloc<dynamic, LocationListState>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59293911/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com