0

我正在开发一个颤振项目,将 api 中的电影详细信息显示到屏幕上。我正在用颤动的cubit来做。但是当我尝试在前端打印数据时它没有显示。当我将其显示打印为moviecategorymodel 的实例时。任何人都知道如何从中获取数据并在我的屏幕上打印。前端代码如下所示:

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:todo_app/cubit/movie_cubit.dart';

class MovieCategoryScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    BlocProvider.of<MovieCubit>(context).fetchCategory();

    return Scaffold(
        appBar: AppBar(title: Text("Movie Category")),
        body: BlocBuilder<MovieCubit, MovieState>(
          builder: (context, state) {
            if (!(state is MovieLoaded))
              return Center(child: CircularProgressIndicator());

            final categories = (state as MovieLoaded).categories;
            print(categories); //showing as instence of moviecategorymodel as output
            return ListView.builder(
                itemCount: categories.length,
                itemBuilder: (context, index) => Card(
                        child: ListTile(
                      title: Text(categories[index].title != null
                          ? categories[index].title
                          : 'nothing to show'),
                    )));
            // return SingleChildScrollView(
            //     child: Column(children: [Text('movies')]));
            // categories.map((e) => _category(e, context)).toList()));
          },
        ));
  }```
4

0 回答 0