filter_box

This commit is contained in:
2024-11-18 14:39:47 +01:00
parent c07551c826
commit ae4290fb47
2 changed files with 68 additions and 22 deletions
+41 -17
View File
@@ -32,6 +32,11 @@ class _MoviesScreenState extends State<MoviesScreen> {
List<GridColumn> _columns = []; List<GridColumn> _columns = [];
late List<Movie> _moviesList; late List<Movie> _moviesList;
String searchText = '';
bool showInit = false;
bool showProg = false;
bool showDone = false;
Logger logger = getLogger(); Logger logger = getLogger();
Future<List<Movie>> generateMovieList() async { Future<List<Movie>> generateMovieList() async {
@@ -139,12 +144,17 @@ class _MoviesScreenState extends State<MoviesScreen> {
} }
Future<void> showMovieDetails(int index) async { Future<void> showMovieDetails(int index) async {
List<DataGridCell<dynamic>> cells = DataGridRow row = movieDataSource.effectiveRows.elementAt(index);
movieDataSource.effectiveRows.elementAt(index).getCells(); List<DataGridCell<dynamic>> cells = row.getCells();
String movieID = cells[MovieColumn.movieID].value.toString(); String movieID = cells[MovieColumn.movieID].value.toString();
bool found = false; bool found = false;
int movieIndex; int movieIndex;
int realIndex;
movieDataSource.clearFilters();
realIndex = movieDataSource.rows.indexOf(row);
for (movieIndex = 0; movieIndex < _moviesList.length; movieIndex++) { for (movieIndex = 0; movieIndex < _moviesList.length; movieIndex++) {
if (_moviesList[movieIndex].movieID == int.parse(movieID)) { if (_moviesList[movieIndex].movieID == int.parse(movieID)) {
@@ -167,7 +177,7 @@ class _MoviesScreenState extends State<MoviesScreen> {
_moviesList[movieIndex].state = m.state; _moviesList[movieIndex].state = m.state;
Movie e = _moviesList[movieIndex]; Movie e = _moviesList[movieIndex];
movieDataSource._movieDataGridRows[index] = DataGridRow(cells: [ movieDataSource._movieDataGridRows[realIndex] = DataGridRow(cells: [
DataGridCell<int>(columnName: 'movieID', value: e.movieID), DataGridCell<int>(columnName: 'movieID', value: e.movieID),
DataGridCell<int>(columnName: 'state', value: e.state), DataGridCell<int>(columnName: 'state', value: e.state),
DataGridCell<String>( DataGridCell<String>(
@@ -180,23 +190,37 @@ class _MoviesScreenState extends State<MoviesScreen> {
DataGridCell<String>(columnName: 'overview', value: e.overview), DataGridCell<String>(columnName: 'overview', value: e.overview),
]); ]);
movieDataSource.updateDataGridSource( for (int i = 0; i < _columns.length; i++) {
rowColumnIndex: RowColumnIndex(index, 0)); movieDataSource.updateDataGridSource(
movieDataSource.updateDataGridSource( rowColumnIndex: RowColumnIndex(realIndex, i));
rowColumnIndex: RowColumnIndex(index, 1)); }
movieDataSource.updateDataGridSource(
rowColumnIndex: RowColumnIndex(index, 2)); // movieDataSource.updateDataGridSource(
movieDataSource.updateDataGridSource( // rowColumnIndex: RowColumnIndex(realIndex, 0));
rowColumnIndex: RowColumnIndex(index, 3)); // movieDataSource.updateDataGridSource(
movieDataSource.updateDataGridSource( // rowColumnIndex: RowColumnIndex(realIndex, 1));
rowColumnIndex: RowColumnIndex(index, 4)); // movieDataSource.updateDataGridSource(
movieDataSource.updateDataGridSource( // rowColumnIndex: RowColumnIndex(realIndex, 2));
rowColumnIndex: RowColumnIndex(index, 5)); // movieDataSource.updateDataGridSource(
// rowColumnIndex: RowColumnIndex(realIndex, 3));
// movieDataSource.updateDataGridSource(
// rowColumnIndex: RowColumnIndex(realIndex, 4));
// movieDataSource.updateDataGridSource(
// rowColumnIndex: RowColumnIndex(realIndex, 5));
} else {} } else {}
filter();
} }
} }
void setFilter(String text, bool showInit, bool showProg, bool showDone) { void setFilter(String text, bool sInit, bool sProg, bool sDone) {
searchText = text;
showInit = sInit;
showProg = sProg;
showDone = sDone;
filter();
}
void filter() {
movieDataSource.clearFilters(); movieDataSource.clearFilters();
if (showInit) if (showInit)
@@ -230,7 +254,7 @@ class _MoviesScreenState extends State<MoviesScreen> {
'movieTitle', 'movieTitle',
FilterCondition( FilterCondition(
type: FilterType.beginsWith, type: FilterType.beginsWith,
value: text, value: searchText,
filterOperator: FilterOperator.and, filterOperator: FilterOperator.and,
filterBehavior: FilterBehavior.stringDataType, filterBehavior: FilterBehavior.stringDataType,
)); ));
+27 -5
View File
@@ -82,6 +82,13 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
late bool initDone = false; late bool initDone = false;
late List<TVShow> _tvshowsList; late List<TVShow> _tvshowsList;
String searchText = '';
bool showInit = false;
bool showProg = false;
bool showDone = false;
Logger logger = getLogger();
Future<List<TVShow>> generateTVShowList() async { Future<List<TVShow>> generateTVShowList() async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
@@ -241,12 +248,18 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
} }
Future<void> showTVShowDetails(int index) async { Future<void> showTVShowDetails(int index) async {
DataGridRow row = tvshowDataSource.effectiveRows.elementAt(index);
List<DataGridCell<dynamic>> cells = List<DataGridCell<dynamic>> cells =
tvshowDataSource.effectiveRows.elementAt(index).getCells(); row.getCells();
String seriesID = cells[TVShowColumn.seriesID].value.toString(); String seriesID = cells[TVShowColumn.seriesID].value.toString();
bool found = false; bool found = false;
int tvShowIndex; int tvShowIndex;
int realIndex;
tvshowDataSource.clearFilters();
realIndex = tvshowDataSource.rows.indexOf(row);
for (tvShowIndex = 0; tvShowIndex < _tvshowsList.length; tvShowIndex++) { for (tvShowIndex = 0; tvShowIndex < _tvshowsList.length; tvShowIndex++) {
if (_tvshowsList[tvShowIndex].seriesID == int.parse(seriesID)) { if (_tvshowsList[tvShowIndex].seriesID == int.parse(seriesID)) {
@@ -272,7 +285,7 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
_tvshowsList[tvShowIndex].seriesState = t.seriesState; _tvshowsList[tvShowIndex].seriesState = t.seriesState;
TVShow e = _tvshowsList[tvShowIndex]; TVShow e = _tvshowsList[tvShowIndex];
tvshowDataSource._tvshowDataGridRows[index] = DataGridRow(cells: [ tvshowDataSource._tvshowDataGridRows[realIndex] = DataGridRow(cells: [
DataGridCell<int>(columnName: 'seriesID', value: e.seriesID), DataGridCell<int>(columnName: 'seriesID', value: e.seriesID),
DataGridCell<int>(columnName: 'seriesState', value: e.seriesState), DataGridCell<int>(columnName: 'seriesState', value: e.seriesState),
DataGridCell<String>(columnName: 'status', value: e.status), DataGridCell<String>(columnName: 'status', value: e.status),
@@ -290,13 +303,22 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
for (int i = 0; i < _columns.length; i++) { for (int i = 0; i < _columns.length; i++) {
tvshowDataSource.updateDataGridSource( tvshowDataSource.updateDataGridSource(
rowColumnIndex: RowColumnIndex(index, i)); rowColumnIndex: RowColumnIndex(realIndex, i));
} }
} else {} } else {}
filter();
} }
} }
void setFilter(String text, bool showInit, bool showProg, bool showDone) { void setFilter(String text, bool sInit, bool sProg, bool sDone) {
searchText = text;
showInit = sInit;
showProg = sProg;
showDone = sDone;
filter();
}
void filter() {
tvshowDataSource.clearFilters(); tvshowDataSource.clearFilters();
if (showInit) if (showInit)
@@ -330,7 +352,7 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
'seriesName', 'seriesName',
FilterCondition( FilterCondition(
type: FilterType.beginsWith, type: FilterType.beginsWith,
value: text, value: searchText,
filterOperator: FilterOperator.and, filterOperator: FilterOperator.and,
filterBehavior: FilterBehavior.stringDataType, filterBehavior: FilterBehavior.stringDataType,
)); ));