Last active
March 31, 2019 08:44
-
-
Save maffan91/20a59c86676ec09204a848f57d71fd31 to your computer and use it in GitHub Desktop.
Example MovieList UI for Flutter
This file contains hidden or 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
import 'package:dismissable_listview/data/movie-list.dart'; | |
import 'package:dismissable_listview/models/movie.dart'; | |
import 'package:dismissable_listview/widgets/movie-card.dart'; | |
import 'package:flutter/material.dart'; | |
class MoviesPage extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() { | |
return _MoviesPageState(); | |
} | |
} | |
class _MoviesPageState extends State<MoviesPage> { | |
final List<Movie> movies = MovieList.getMovies(); | |
Widget _buildMoviesList() { | |
return Container( | |
child: movies.length > 0 | |
? ListView.builder( | |
itemCount: movies.length, | |
itemBuilder: (BuildContext context, int index) { | |
return Dismissible( | |
onDismissed: (DismissDirection direction) { | |
setState(() { | |
movies.removeAt(index); | |
}); | |
}, | |
secondaryBackground: Container( | |
child: Center( | |
child: Text( | |
'Delete', | |
style: TextStyle(color: Colors.white), | |
), | |
), | |
color: Colors.red, | |
), | |
background: Container(), | |
child: MovieCard(movie: movies[index]), | |
key: UniqueKey(), | |
direction: DismissDirection.endToStart, | |
); | |
}, | |
) | |
: Center(child: Text('No Items')), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Movies'), | |
), | |
body: _buildMoviesList(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment