initializing
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
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 {
|
||||
int movieID;
|
||||
String movieTitle;
|
||||
String overview;
|
||||
DateTime releaseDate;
|
||||
int state;
|
||||
String resolution;
|
||||
|
||||
Movie({
|
||||
required this.movieID,
|
||||
required this.movieTitle,
|
||||
required this.overview,
|
||||
required this.releaseDate,
|
||||
required this.state,
|
||||
required this.resolution,
|
||||
});
|
||||
|
||||
factory Movie.fromJson(Map<String, dynamic> json) {
|
||||
return Movie(
|
||||
movieID: int.parse(json['movieID']),
|
||||
movieTitle: json['movieTitle'] as String,
|
||||
overview: json['overview'] as String,
|
||||
releaseDate: DateTime.parse(json['releaseDate']),
|
||||
state: int.parse(json['state']),
|
||||
resolution: json['resolution'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MovieDataSource extends DataGridSource {
|
||||
/// Creates the employee data source class with required details.
|
||||
MovieDataSource(this.movies) {
|
||||
buildDataGridRow();
|
||||
}
|
||||
|
||||
void buildDataGridRow() {
|
||||
_movieDataGridRows = movies
|
||||
.map<DataGridRow>((e) => DataGridRow(cells: [
|
||||
DataGridCell<int>(columnName: 'movieID', value: e.movieID),
|
||||
DataGridCell<int>(columnName: 'state', value: e.state),
|
||||
DataGridCell<String>(
|
||||
columnName: 'movieTitle', value: e.movieTitle),
|
||||
DataGridCell<String>(
|
||||
columnName: 'releaseDate',
|
||||
value: DateFormat('yyyy-MM-dd').format(e.releaseDate)),
|
||||
DataGridCell<String>(
|
||||
columnName: 'resolution', value: e.resolution),
|
||||
DataGridCell<String>(columnName: 'overview', value: e.overview),
|
||||
]))
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<Movie> movies = [];
|
||||
|
||||
List<DataGridRow> _movieDataGridRows = [];
|
||||
|
||||
@override
|
||||
List<DataGridRow> get rows => _movieDataGridRows;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user