From ae4290fb477bf18f082ec2360ba58bf10aec8778 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Mon, 18 Nov 2024 14:39:47 +0100 Subject: [PATCH] filter_box --- lib/widgets/movies/list_screen.dart | 58 ++++++++++++++++++++-------- lib/widgets/tvshows/list_screen.dart | 32 ++++++++++++--- 2 files changed, 68 insertions(+), 22 deletions(-) diff --git a/lib/widgets/movies/list_screen.dart b/lib/widgets/movies/list_screen.dart index 6b0c8d0..85f6817 100644 --- a/lib/widgets/movies/list_screen.dart +++ b/lib/widgets/movies/list_screen.dart @@ -32,6 +32,11 @@ class _MoviesScreenState extends State { List _columns = []; late List _moviesList; + String searchText = ''; + bool showInit = false; + bool showProg = false; + bool showDone = false; + Logger logger = getLogger(); Future> generateMovieList() async { @@ -139,12 +144,17 @@ class _MoviesScreenState extends State { } Future showMovieDetails(int index) async { - List> cells = - movieDataSource.effectiveRows.elementAt(index).getCells(); + DataGridRow row = movieDataSource.effectiveRows.elementAt(index); + List> cells = row.getCells(); String movieID = cells[MovieColumn.movieID].value.toString(); bool found = false; int movieIndex; + int realIndex; + + movieDataSource.clearFilters(); + + realIndex = movieDataSource.rows.indexOf(row); for (movieIndex = 0; movieIndex < _moviesList.length; movieIndex++) { if (_moviesList[movieIndex].movieID == int.parse(movieID)) { @@ -167,7 +177,7 @@ class _MoviesScreenState extends State { _moviesList[movieIndex].state = m.state; Movie e = _moviesList[movieIndex]; - movieDataSource._movieDataGridRows[index] = DataGridRow(cells: [ + movieDataSource._movieDataGridRows[realIndex] = DataGridRow(cells: [ DataGridCell(columnName: 'movieID', value: e.movieID), DataGridCell(columnName: 'state', value: e.state), DataGridCell( @@ -180,23 +190,37 @@ class _MoviesScreenState extends State { DataGridCell(columnName: 'overview', value: e.overview), ]); - movieDataSource.updateDataGridSource( - rowColumnIndex: RowColumnIndex(index, 0)); - movieDataSource.updateDataGridSource( - rowColumnIndex: RowColumnIndex(index, 1)); - movieDataSource.updateDataGridSource( - rowColumnIndex: RowColumnIndex(index, 2)); - movieDataSource.updateDataGridSource( - rowColumnIndex: RowColumnIndex(index, 3)); - movieDataSource.updateDataGridSource( - rowColumnIndex: RowColumnIndex(index, 4)); - movieDataSource.updateDataGridSource( - rowColumnIndex: RowColumnIndex(index, 5)); + for (int i = 0; i < _columns.length; i++) { + movieDataSource.updateDataGridSource( + rowColumnIndex: RowColumnIndex(realIndex, i)); + } + + // movieDataSource.updateDataGridSource( + // rowColumnIndex: RowColumnIndex(realIndex, 0)); + // movieDataSource.updateDataGridSource( + // rowColumnIndex: RowColumnIndex(realIndex, 1)); + // movieDataSource.updateDataGridSource( + // rowColumnIndex: RowColumnIndex(realIndex, 2)); + // movieDataSource.updateDataGridSource( + // rowColumnIndex: RowColumnIndex(realIndex, 3)); + // movieDataSource.updateDataGridSource( + // rowColumnIndex: RowColumnIndex(realIndex, 4)); + // movieDataSource.updateDataGridSource( + // rowColumnIndex: RowColumnIndex(realIndex, 5)); } 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(); if (showInit) @@ -230,7 +254,7 @@ class _MoviesScreenState extends State { 'movieTitle', FilterCondition( type: FilterType.beginsWith, - value: text, + value: searchText, filterOperator: FilterOperator.and, filterBehavior: FilterBehavior.stringDataType, )); diff --git a/lib/widgets/tvshows/list_screen.dart b/lib/widgets/tvshows/list_screen.dart index deb7154..63f4d59 100644 --- a/lib/widgets/tvshows/list_screen.dart +++ b/lib/widgets/tvshows/list_screen.dart @@ -82,6 +82,13 @@ class _TVShowsScreenState extends State { late bool initDone = false; late List _tvshowsList; + String searchText = ''; + bool showInit = false; + bool showProg = false; + bool showDone = false; + + Logger logger = getLogger(); + Future> generateTVShowList() async { SharedPreferences prefs = await SharedPreferences.getInstance(); @@ -241,12 +248,18 @@ class _TVShowsScreenState extends State { } Future showTVShowDetails(int index) async { + DataGridRow row = tvshowDataSource.effectiveRows.elementAt(index); List> cells = - tvshowDataSource.effectiveRows.elementAt(index).getCells(); + row.getCells(); String seriesID = cells[TVShowColumn.seriesID].value.toString(); bool found = false; int tvShowIndex; + int realIndex; + + tvshowDataSource.clearFilters(); + + realIndex = tvshowDataSource.rows.indexOf(row); for (tvShowIndex = 0; tvShowIndex < _tvshowsList.length; tvShowIndex++) { if (_tvshowsList[tvShowIndex].seriesID == int.parse(seriesID)) { @@ -272,7 +285,7 @@ class _TVShowsScreenState extends State { _tvshowsList[tvShowIndex].seriesState = t.seriesState; TVShow e = _tvshowsList[tvShowIndex]; - tvshowDataSource._tvshowDataGridRows[index] = DataGridRow(cells: [ + tvshowDataSource._tvshowDataGridRows[realIndex] = DataGridRow(cells: [ DataGridCell(columnName: 'seriesID', value: e.seriesID), DataGridCell(columnName: 'seriesState', value: e.seriesState), DataGridCell(columnName: 'status', value: e.status), @@ -290,13 +303,22 @@ class _TVShowsScreenState extends State { for (int i = 0; i < _columns.length; i++) { tvshowDataSource.updateDataGridSource( - rowColumnIndex: RowColumnIndex(index, i)); + rowColumnIndex: RowColumnIndex(realIndex, i)); } } 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(); if (showInit) @@ -330,7 +352,7 @@ class _TVShowsScreenState extends State { 'seriesName', FilterCondition( type: FilterType.beginsWith, - value: text, + value: searchText, filterOperator: FilterOperator.and, filterBehavior: FilterBehavior.stringDataType, ));