movie and tvshow list

main
Herwig Birke 2 years ago
parent 6dbf2b2f31
commit 87aeb70c27

@ -3,6 +3,42 @@ import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
class EpisodeCount {
int season;
int cnt;
EpisodeCount({
required this.season,
required this.cnt,
});
factory EpisodeCount.fromJson(Map<String, dynamic> json) {
return EpisodeCount(
season: int.parse(json['seasonNumber']),
cnt: int.parse(json['cnt']),
);
}
}
class Season {
int seasonNumber;
int seasonID;
String state;
Season({
required this.seasonNumber,
required this.seasonID,
required this.state,
});
factory Season.fromJson(Map<String, dynamic> json) {
return Season(
seasonNumber: int.parse(json['seasonNumber']),
seasonID: int.parse(json['seasonID']),
state: json['state']);
}
}
class TVShow {
int seriesID;
String seriesName;
@ -11,6 +47,7 @@ class TVShow {
String resolution;
int cliffhanger;
String status;
List<Season> seasonStatus;
TVShow({
required this.seriesID,
@ -20,6 +57,7 @@ class TVShow {
required this.resolution,
required this.cliffhanger,
required this.status,
required this.seasonStatus,
});
factory TVShow.fromJson(Map<String, dynamic> json) {
@ -56,56 +94,8 @@ class TVShow {
resolution: json['resolution'],
status: json['status'],
cliffhanger: int.parse(json['cliffhanger']),
seasonStatus:
json['seasons'].map<Season>((json) => Season.fromJson(json)).toList(),
);
}
}
class TVShowDataSource extends DataGridSource {
/// Creates the employee data source class with required details.
TVShowDataSource(this.tvshows) {
buildDataGridRow();
}
void buildDataGridRow() {
_tvshowDataGridRows = tvshows
.map<DataGridRow>((e) => DataGridRow(cells: [
DataGridCell<int>(columnName: 'seriesID', value: e.seriesID),
DataGridCell<int>(
columnName: 'seriesState', value: e.seriesState),
DataGridCell<String>(columnName: 'status', value: e.status),
DataGridCell<int>(
columnName: 'cliffhanger', value: e.cliffhanger),
DataGridCell<String>(
columnName: 'seriesName', value: e.seriesName),
DataGridCell<String>(
columnName: 'firstAired',
value: DateFormat('yyyy-MM-dd').format(e.firstAired)),
DataGridCell<String>(
columnName: 'resolution', value: e.resolution),
]))
.toList();
}
List<TVShow> tvshows = [];
List<DataGridRow> _tvshowDataGridRows = [];
@override
List<DataGridRow> get rows => _tvshowDataGridRows;
@override
DataGridRowAdapter buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((e) {
return Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(8.0),
child: Text(e.value.toString()),
);
}).toList());
}
void updateDataGrid() {
notifyListeners();
}
}

@ -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);
List<EpisodeCount> _episodecount = await episodeList
.map<EpisodeCount>((json) => EpisodeCount.fromJson(json))
.toList();
episodeCount = _episodecount;
maxSeason = mSeason;
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),

Loading…
Cancel
Save