save new movie

This commit is contained in:
2025-04-15 16:49:08 +02:00
parent 72aa10aa0d
commit 2db1954585
3 changed files with 285 additions and 99 deletions
+13 -7
View File
@@ -16,7 +16,12 @@ import 'package:tmdb_api/tmdb_api.dart' as TMDB;
// ignore: must_be_immutable
class AddMovieScreen extends StatefulWidget {
AddMovieScreen({
final Function(Movie) addMovieToList;
final Function() addMovieFinished;
AddMovieScreen(
this.addMovieToList,
this.addMovieFinished, {
super.key,
});
@@ -35,6 +40,8 @@ class _AddMovieScreenState extends State<AddMovieScreen> {
List<Movie> movieList = [];
late MovieSearchList movieSearchList;
late Function(Movie) addMovieToList;
late Function() addMovieFinished;
static const headerStyle = TextStyle(
color: Color(0xffffffff), fontSize: 18, fontWeight: FontWeight.bold);
@@ -42,6 +49,8 @@ class _AddMovieScreenState extends State<AddMovieScreen> {
@override
Widget build(BuildContext context) {
addMovieToList = widget.addMovieToList;
addMovieFinished = widget.addMovieFinished;
movieSearchList = MovieSearchList(movieList: movieList);
return Scaffold(
@@ -376,15 +385,15 @@ class _AddMovieScreenState extends State<AddMovieScreen> {
if (movie.state == 1) {
somethingFound = true;
addMovie(movieList[i].movieID);
addMovieToList(movie);
}
}
addMovieFinished();
return somethingFound;
}
Future<bool> addMovie(int movieID) async {
logger.i('addMovie');
String lang = 'de';
if (!searchGerman || searchEnglish) {
@@ -400,10 +409,8 @@ class _AddMovieScreenState extends State<AddMovieScreen> {
appendToResponse: 'credits,external_ids',
);
// logger.i(response);
Movie movie = Movie.fromJsonDynamic(response);
writeToDB(movie);
// logger.i('${movie.movieTitle} (${movie.movieID})');
return true;
}
@@ -435,8 +442,7 @@ class _AddMovieScreenState extends State<AddMovieScreen> {
'movieTitle': movie.movieTitle,
'originalTitle': movie.originalTitle,
'overview': movie.overview,
'releaseDate':
DateFormat('yyyy-MM-dd').format(movie.releaseDate),
'releaseDate': DateFormat('yyyy-MM-dd').format(movie.releaseDate),
'resolution': movie.resolution,
'state': movie.state.toString(),
'backdropPath': movie.backdropPath,
+89 -58
View File
@@ -1,11 +1,11 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:multimedia/widgets/movies/add/add_screen.dart';
import 'package:multimedia/widgets/movies/details/details_screen.dart';
import 'package:multimedia/widgets/movies/filter_box.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
@@ -195,19 +195,6 @@ class _MoviesScreenState extends State<MoviesScreen> {
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();
}
@@ -261,6 +248,7 @@ class _MoviesScreenState extends State<MoviesScreen> {
));
}
late SfDataGrid dataGrid;
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -279,9 +267,6 @@ class _MoviesScreenState extends State<MoviesScreen> {
tooltip: 'Add Movie',
onPressed: () {
addMovie();
// if (save()) {
// Navigator.pop(context, movieDetails);
// }
},
),
IconButton(
@@ -300,46 +285,48 @@ class _MoviesScreenState extends State<MoviesScreen> {
child: FutureBuilder<Object>(
future: generateMovieList(),
builder: (context, data) {
return data.hasData
? SfDataGridTheme(
data: const SfDataGridThemeData(
headerColor: Color(0xff009889),
),
child: SfDataGrid(
source: movieDataSource,
selectionMode: SelectionMode.single,
navigationMode: GridNavigationMode.row,
columns: _columns,
controller: _dataGridController,
columnWidthMode: ColumnWidthMode.auto,
columnWidthCalculationRange:
ColumnWidthCalculationRange.allRows,
onCellTap: (DataGridCellTapDetails details) {
int index = details.rowColumnIndex.rowIndex - 1;
if (index < 0) {
return;
}
showMovieDetails(index);
},
onCellDoubleTap:
(DataGridCellDoubleTapDetails details) {
print(details.rowColumnIndex);
},
onCellLongPress:
(DataGridCellLongPressDetails details) {
print(details.rowColumnIndex);
},
onCellSecondaryTap: (DataGridCellTapDetails details) {
print(details.rowColumnIndex);
},
),
)
: const Center(
child: CircularProgressIndicator(
strokeWidth: 2,
value: 0.8,
),
);
if (data.hasData) {
dataGrid = SfDataGrid(
source: movieDataSource,
selectionMode: SelectionMode.single,
navigationMode: GridNavigationMode.row,
columns: _columns,
controller: _dataGridController,
columnWidthMode: ColumnWidthMode.auto,
columnWidthCalculationRange:
ColumnWidthCalculationRange.allRows,
onCellTap: (DataGridCellTapDetails details) {
int index = details.rowColumnIndex.rowIndex - 1;
if (index < 0) {
return;
}
showMovieDetails(index);
},
onCellDoubleTap: (DataGridCellDoubleTapDetails details) {
print(details.rowColumnIndex);
},
onCellLongPress: (DataGridCellLongPressDetails details) {
print(details.rowColumnIndex);
},
onCellSecondaryTap: (DataGridCellTapDetails details) {
print(details.rowColumnIndex);
},
);
return SfDataGridTheme(
data: const SfDataGridThemeData(
headerColor: Color(0xff009889),
),
child: dataGrid,
);
} else {
return const Center(
child: CircularProgressIndicator(
strokeWidth: 2,
value: 0.8,
),
);
}
},
),
),
@@ -347,9 +334,53 @@ class _MoviesScreenState extends State<MoviesScreen> {
);
}
void addMovieToList(Movie movie) {
String movieTitle = movie.movieTitle.toUpperCase();
_moviesList.add(movie);
DataGridRow newRow = DataGridRow(cells: [
DataGridCell<int>(columnName: 'movieID', value: movie.movieID),
DataGridCell<int>(columnName: 'state', value: movie.state),
DataGridCell<String>(
columnName: 'backdropPath', value: movie.backdropPath),
DataGridCell<String>(columnName: 'movieTitle', value: movie.movieTitle),
DataGridCell<String>(
columnName: 'releaseDate',
value: DateFormat('yyyy-MM-dd').format(movie.releaseDate)),
DataGridCell<String>(columnName: 'resolution', value: movie.resolution),
DataGridCell<String>(columnName: 'overview', value: movie.overview),
]);
int rowNum = -1;
for (int i = 0; i < movieDataSource._movieDataGridRows.length; i++) {
DataGridRow tmpRow = movieDataSource._movieDataGridRows[i];
List<DataGridCell> tmpCells = tmpRow.getCells();
String tmpTitle = tmpCells[3].value.toString();
if (tmpTitle.toUpperCase().compareTo(movieTitle) >= 0) {
rowNum = i;
break;
}
}
if (rowNum == -1) {
rowNum = movieDataSource._movieDataGridRows.length;
}
movieDataSource._movieDataGridRows.insert(rowNum, newRow);
movieDataSource.updateDataGrid();
}
void addMovieFinished() {}
void addMovie() {
final m = Navigator.push(
context, MaterialPageRoute(builder: (ctx) => AddMovieScreen()));
context,
MaterialPageRoute(
builder: (ctx) =>
AddMovieScreen(addMovieToList, addMovieFinished)));
}
void searchMovie() {