movie and tvshow list
This commit is contained in:
@@ -26,9 +26,10 @@ class TVShowsScreen extends StatefulWidget {
|
||||
class _TVShowsScreenState extends State<TVShowsScreen> {
|
||||
final DataGridController _dataGridController = DataGridController();
|
||||
late int maxSeason;
|
||||
late Map<int, int> episodeCount;
|
||||
late List<EpisodeCount> episodeCount;
|
||||
late TVShowDataSource tvshowDataSource;
|
||||
List<GridColumn> _columns = [];
|
||||
late bool initDone = false;
|
||||
|
||||
Future<List<TVShow>> generateTVShowList() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
@@ -37,8 +38,6 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
|
||||
String? dbHost = prefs.getString('dbHost');
|
||||
String? dbPath = prefs.getString('dbPath');
|
||||
|
||||
print(dbHost);
|
||||
|
||||
Uri url = Uri(
|
||||
scheme: dbProtocol,
|
||||
host: dbHost,
|
||||
@@ -52,27 +51,53 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
|
||||
final response = await http.get(url);
|
||||
bool? error;
|
||||
String? errorMessage;
|
||||
String? mSeason;
|
||||
|
||||
Map<String, dynamic> tvshows = json.decode(response.body);
|
||||
error = tvshows['error'];
|
||||
errorMessage = tvshows['errmsg'];
|
||||
var mSeason = tvshows['maxSeason'];
|
||||
mSeason = tvshows['maxSeason'];
|
||||
|
||||
var tvshowList = tvshows['tvshows'];
|
||||
// var episodeList = tvshows['episodeCount'];
|
||||
//
|
||||
// for (var episode in episodeList) {
|
||||
// episodeCount[episode['seasonNumber']] = episode['cnr'];
|
||||
// }
|
||||
var episodeList = tvshows['episodeCount'];
|
||||
|
||||
if (mSeason != null) {
|
||||
if (int.tryParse(mSeason!) != null) {
|
||||
maxSeason = int.parse(mSeason);
|
||||
}
|
||||
}
|
||||
|
||||
List<TVShow> _tvshows =
|
||||
await tvshowList.map<TVShow>((json) => TVShow.fromJson(json)).toList();
|
||||
tvshowDataSource = TVShowDataSource(_tvshows);
|
||||
tvshowDataSource = TVShowDataSource(_tvshows, maxSeason);
|
||||
|
||||
maxSeason = mSeason;
|
||||
List<EpisodeCount> _episodecount = await episodeList
|
||||
.map<EpisodeCount>((json) => EpisodeCount.fromJson(json))
|
||||
.toList();
|
||||
|
||||
episodeCount = _episodecount;
|
||||
|
||||
if (initDone == false) {
|
||||
addSeasonColumns(maxSeason);
|
||||
}
|
||||
|
||||
initDone = true;
|
||||
|
||||
return _tvshows;
|
||||
}
|
||||
|
||||
void addSeasonColumns(int maxSeason) {
|
||||
for (int x = 1; x <= maxSeason; x++) {
|
||||
_columns.add(GridColumn(
|
||||
columnName: 'season$x',
|
||||
columnWidthMode: ColumnWidthMode.auto,
|
||||
label: Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('Season $x'))));
|
||||
}
|
||||
}
|
||||
|
||||
List<GridColumn> getColumns() {
|
||||
return <GridColumn>[
|
||||
GridColumn(
|
||||
@@ -128,13 +153,6 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: const Text('Resolution'))),
|
||||
GridColumn(
|
||||
columnName: 'season1',
|
||||
columnWidthMode: ColumnWidthMode.auto,
|
||||
label: Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: const Text('Season 1'))),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -178,10 +196,25 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
|
||||
|
||||
class TVShowDataSource extends DataGridSource {
|
||||
/// Creates the employee data source class with required details.
|
||||
TVShowDataSource(this.tvshows) {
|
||||
TVShowDataSource(this.tvshows, this.maxSeason) {
|
||||
buildDataGridRow();
|
||||
}
|
||||
|
||||
List<DataGridCell> setSeasonData(int maxSeason, List<Season> seasonList) {
|
||||
List<DataGridCell> dataGridCell = [];
|
||||
|
||||
for (int x = 1; x <= maxSeason; x++) {
|
||||
String status = '';
|
||||
|
||||
if (seasonList.length <= x) {
|
||||
status = seasonList[x].state;
|
||||
}
|
||||
dataGridCell.add(DataGridCell(columnName: 'season$x', value: 'status'));
|
||||
}
|
||||
|
||||
return dataGridCell;
|
||||
}
|
||||
|
||||
void buildDataGridRow() {
|
||||
_tvshowDataGridRows = tvshows
|
||||
.map<DataGridRow>((e) => DataGridRow(cells: [
|
||||
@@ -198,12 +231,13 @@ class TVShowDataSource extends DataGridSource {
|
||||
value: DateFormat('yyyy-MM-dd').format(e.firstAired)),
|
||||
DataGridCell<String>(
|
||||
columnName: 'resolution', value: e.resolution),
|
||||
DataGridCell(columnName: 'season1', value: ''),
|
||||
...setSeasonData(maxSeason, e.seasonStatus),
|
||||
]))
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<TVShow> tvshows = [];
|
||||
int maxSeason;
|
||||
|
||||
List<DataGridRow> _tvshowDataGridRows = [];
|
||||
|
||||
@@ -242,13 +276,14 @@ class TVShowDataSource extends DataGridSource {
|
||||
}
|
||||
}
|
||||
|
||||
// if (e.columnName.startsWith('season')) {
|
||||
// return Container(
|
||||
// alignment: Alignment.center,
|
||||
// padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
// child: Icon(Icons.location_on),
|
||||
// );
|
||||
// }
|
||||
if (e.columnName.startsWith('season')) {
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Icon(Icons.location_on),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
|
||||
Reference in New Issue
Block a user