68 lines
1.8 KiB
Dart
68 lines
1.8 KiB
Dart
|
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();
|
||
|
}
|
||
|
},
|
||
|
));
|
||
|
}
|
||
|
}
|