Created
July 11, 2020 08:40
-
-
Save ashishrawat2911/989377a5fc61da2a9d34be155c584bf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
@override | |
void initState() { | |
context.bloc<MovieBloc>().add(LoadMovies()); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Movies"), | |
), | |
body: BlocBuilder<MovieBloc, ResultState<List<Movie>>>( | |
builder: (BuildContext context, ResultState<List<Movie>> state) { | |
return state.when( | |
loading: () { | |
return Center(child: CircularProgressIndicator()); | |
}, | |
idle: () { | |
return Container(); | |
}, | |
data: (List<Movie> data) { | |
return dataWidget(data); | |
}, | |
error: (NetworkExceptions error) { | |
return Text(NetworkExceptions.getErrorMessage(error)); | |
}, | |
); | |
}, | |
), | |
); | |
} | |
Widget dataWidget(List<Movie> data) { | |
return ListView.builder( | |
itemCount: data.length, | |
itemBuilder: (BuildContext context, int index) { | |
return Container( | |
height: 300, | |
width: 300, | |
child: Card( | |
elevation: 1, | |
child: Image.network( | |
"https://image.tmdb.org/t/p/w342${data[index].posterPath}", | |
), | |
), | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment