I have a class apart to be able to use hive and I want to receive a list of an api that I'm consuming,but when I call my class who gets a list it gives me this error
class PersistStorage {
sendData(List<Movie> movie) async {
var box = await Hive.openBox('data');
box.put("movies", movie);
}
}
FutureBuilder where I call my class:
class GridViewMovies extends StatefulWidget {
double _crossAxisSpacing = 15, _mainAxisSpacing = 12, _aspectRatio = 1;
PersistStorage storage;
GridViewMovies({Key key}) : super(key: key);
@override
_GridViewMoviesState createState() => _GridViewMoviesState();
}
class _GridViewMoviesState extends State<GridViewMovies> {
BlocMovies movieBloc;
@override
Widget build(BuildContext context) {
movieBloc = BlocProvider.of(context);
return FutureBuilder(
future: movieBloc.getlistMovies(),
builder: (BuildContext context, AsyncSnapshot<MoviesModel> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(
child: CircularProgressIndicator(),
);
break;
case ConnectionState.none:
return Center(
child: CircularProgressIndicator(),
);
break;
case ConnectionState.done:
if (snapshot.data == null) {
return Center(child: Text("Intenta mas tarde"));
}
//here call my function .......................
widget.storage.sendData(snapshot.data.items);
return Center(
child: movieList(context, snapshot.data.items),
);
break;
case ConnectionState.active:
if (snapshot.data == null) {
return Center(child: Text("Intenta mas tarde"));
}
return Center(
child: movieList(context, snapshot.data.items),
);
break;
default:
}
});
}
and because the class only serves me to call my function but throws me that mistake, any idea to solve this problem?