'how to fetch data into listview? [flutter]
i want to fetch the data into listview, but it keep crashing, i already fetch the api and put it in UI. how is the alternative way to fetch the api, help, i need any answer
class NowPlayingPages extends StatelessWidget {
const NowPlayingPages({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.blue
),
);
}
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
List now_playing = [];
final String apikey ='0780e6689e1189ea7b55c2a7ef7cc969';
final readaccesstoken = 'eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwNzgwZTY2ODllMTE4OWVhN2I1NWMyYTdlZjdjYzk2OSIsInN1YiI6IjYyNmEzMjQ0OTBkZGUwMDBhNmUyYjEyMSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.tmT_rASDXvRLFurM3MHnEuDxYCpfjEBJdC2hfXnULGs';
@override
void initState(){
loadmovies();
super.initState();
}
loadmovies()async{
TMDB tmdbWithCustomLogs = TMDB(ApiKeys(apikey, readaccesstoken),
logConfig: ConfigLogger(
showLogs: true,
showErrorLogs: true
));
Map now_playingresult = await tmdbWithCustomLogs.v3.movies.getNowPlaying();
setState(() {
now_playing = now_playingresult['results'];
});
}
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
modified_text(text:'Now Playing', size: 26,color: Colors.white,),
SizedBox(height: 37,),
Container(height: 297,
child: ListView.builder(
itemCount: now_playing.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index){
return InkWell(
child: Container(
width: 167,
child: Column(
children: [
Container(
height:227,
decoration: BoxDecoration(image :DecorationImage(
image: NetworkImage(
'https://image.tmdb.org/t/p/w500' + now_playing[index]['poster_path']
)
)),
),
Container(child: modified_text(text:now_playing[index]['title']!=null?
now_playing[index]['title']:'Loading', size: 14, color: Colors.white,))
],
),
),
);
}),)
],
),
);
}
}
please help me to find the bug, i don't really know where the error is, im new to flutter
this is the detail of how i fetch the data:
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
List now_playing = [];
final String apikey ='0780e6689e1189ea7b55c2a7ef7cc969';
final readaccesstoken = 'eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwNzgwZTY2ODllMTE4OWVhN2I1NWMyYTdlZjdjYzk2OSIsInN1YiI6IjYyNmEzMjQ0OTBkZGUwMDBhNmUyYjEyMSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.tmT_rASDXvRLFurM3MHnEuDxYCpfjEBJdC2hfXnULGs';
@override
void initState(){
loadmovies();
super.initState();
}
loadmovies()async{
TMDB tmdbWithCustomLogs = TMDB(ApiKeys(apikey, readaccesstoken),
logConfig: ConfigLogger(
showLogs: true,
showErrorLogs: true
));
Map now_playingresult = await tmdbWithCustomLogs.v3.movies.getNowPlaying();
setState(() {
now_playing = now_playingresult['results'];
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
