类型'int'不是类型'(int)=> void'的子类型

时间:2020-03-07 03:40:00

标签: flutter stream bloc

我正在尝试使用typedef使用别名。这是宣言

typedef OnPosterCallBack = void Function (int movieId);

我想像onTap()一样在onTap: () => onPosterCallBack(movieItems.movieId)上使用此回调。

我的gridview小部件看起来像:

用于:

Widget build(BuildContext context) {
    final MoviesBloc bloc = BlocProvider.of<MoviesBloc>(context);
    return StreamBuilder<MoviesViewModel>(
      stream: bloc.moviesStream,
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          if (snapshot.data != null) {
            return buildGrid(snapshot.data, (movieId) {
              bloc.selectedMovieModelStream.listen(movieId);
              Navigator.pushReplacement(
                context,
                MaterialPageRoute(
                      builder: (context) => MovieDetailsScreen()));
            });
          } else {
            return Center(
              child: Text('No Image Found'),
            );
          }
        }
        return Center(child: CircularProgressIndicator());
      },
    );
  }

我想导航到电影详细信息页面,并将movieId发送到下一个小部件,以便我可以获取电影详细信息请求所需的值。

我正在从集团发送电影ID,即:

      PublishSubject<int>();
  Stream<int> get selectedMovieModelStream =>
      _selectedMovieIDPipe.stream;

  MoviesBloc({DiscoverMoviesService discoverMoviesService}) {
    _discoverMoviesService = discoverMoviesService ??= DiscoverMoviesService();
    _selectedMovieIDPipe.listen(_selectedMovieModel);
  }

  _selectedMovieModel(int movieId) {
    if (_model != null) {
      var movies = _model.movies.expand((itemId) => _model.movies).toList();
      _model.movies.first = movies.firstWhere((movie) => movie.movieId == movieId);
    }
  }

如何解决以下错误:

The following assertion was thrown while handling a gesture: type 'int' is not a subtype of type '(int) => void'

0 个答案:

没有答案