addactor, addtag dialogs

This commit is contained in:
2022-08-30 23:25:21 +02:00
parent b0f913f8d1
commit 405d7e420e
10 changed files with 302 additions and 64 deletions

View File

@ -0,0 +1,67 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import '../api/actor_api.dart';
import '../api/api.dart';
import '../log/log.dart';
import '../screen_loading.dart';
import '../types/actor.dart';
class AddActorDialog extends StatefulWidget {
const AddActorDialog({Key? key, required this.movieId}) : super(key: key);
final int movieId;
@override
State<AddActorDialog> createState() => _AddActorDialogState();
}
class _AddActorDialogState extends State<AddActorDialog> {
late Future<List<Actor>> actors = loadAllActors();
Future<void> addActorToVideo(int actorId) async {
final data = await API.query("actor", "addActorToVideo",
{'ActorId': actorId, 'MovieId': widget.movieId});
final d = jsonDecode(data);
if (d["result"] != "success") {
Log.w("couldn't add actor to video");
}
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return AlertDialog(
scrollable: true,
title: Text("Add Actor"),
content: FutureBuilder(
future: actors,
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text("Error");
} else if (snapshot.hasData) {
final data = snapshot.data! as List<Actor>;
return Column(
mainAxisSize: MainAxisSize.min,
children: data
.map((e) => ListTile(
title: Text(e.name),
onTap: () async {
await addActorToVideo(e.actorId);
Navigator.pop(context, e);
},
))
.toList(),
);
} else {
return ScreenLoading();
}
},
));
}
}

View File

@ -0,0 +1,76 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import '../api/api.dart';
import '../log/log.dart';
import '../screen_loading.dart';
import '../types/tag.dart';
class AddTagDialog extends StatefulWidget {
const AddTagDialog({Key? key, required this.movieId}) : super(key: key);
final int movieId;
@override
State<AddTagDialog> createState() => _AddTagDialogState();
}
class _AddTagDialogState extends State<AddTagDialog> {
late Future<List<Tag>> tags = loadAllTags();
Future<List<Tag>> loadAllTags() async {
final data = await API.query("tags", "getAllTags", {});
final d = (jsonDecode(data) ?? []) as List<dynamic>;
final tags = d.map((e) => Tag.fromJson(e)).toList(growable: false);
return tags;
}
Future<void> addTagToVideo(int tagId) async {
final data = await API
.query("tags", "addTag", {'TagId': tagId, 'MovieId': widget.movieId});
final d = jsonDecode(data);
if (d["result"] != "success") {
Log.w("couldn't add actor to video");
}
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return AlertDialog(
scrollable: true,
title: Text("Add Tag"),
content: FutureBuilder(
future: tags,
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text("Error");
} else if (snapshot.hasData) {
final data = snapshot.data! as List<Tag>;
return Column(
mainAxisSize: MainAxisSize.min,
children: data
.map(
(e) => ListTile(
title: Text(e.tagName),
onTap: () async {
await addTagToVideo(e.tagId);
Navigator.pop(context, e);
},
),
)
.toList(),
);
} else {
return ScreenLoading();
}
},
));
}
}