movie and tvshow list

This commit is contained in:
2024-03-29 15:25:06 +01:00
parent fcab51f7ab
commit cc0fccd76d
9 changed files with 372 additions and 75 deletions
-2
View File
@@ -1,8 +1,6 @@
import 'dart:convert';
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
class Movie {
+111
View File
@@ -0,0 +1,111 @@
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
class TVShow {
int seriesID;
String seriesName;
DateTime firstAired;
int seriesState;
String resolution;
int cliffhanger;
String status;
TVShow({
required this.seriesID,
required this.seriesName,
required this.firstAired,
required this.seriesState,
required this.resolution,
required this.cliffhanger,
required this.status,
});
factory TVShow.fromJson(Map<String, dynamic> json) {
int seriesState = 0;
List<String> stateList = json['seriesState'].toString().split(',');
bool hasInit = false;
bool hasProg = false;
bool hasDone = false;
for (String state in stateList) {
if (state[0] == '1') {
hasInit = true;
} else if (state[0] == '2') {
hasProg = true;
} else if (state[0] == '3') {
hasDone = true;
}
}
if (hasProg) {
seriesState = 2;
} else if (hasInit) {
seriesState = 1;
} else if (hasDone) {
seriesState = 3;
}
return TVShow(
seriesID: int.parse(json['seriesID']),
seriesName: json['seriesName'],
firstAired: DateTime.parse(json['firstAired']),
seriesState: seriesState,
resolution: json['resolution'],
status: json['status'],
cliffhanger: int.parse(json['cliffhanger']),
);
}
}
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();
}
}