56 lines
1.6 KiB
Dart
56 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../api/actor_api.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();
|
|
|
|
@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>;
|
|
data.sort((a, b) =>
|
|
a.name.toLowerCase().compareTo(b.name.toLowerCase()));
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: data
|
|
.map((e) => ListTile(
|
|
title: Text(e.name),
|
|
onTap: () async {
|
|
await addActorToVideo(e.actorId, widget.movieId);
|
|
Navigator.pop(context, e);
|
|
},
|
|
))
|
|
.toList(),
|
|
);
|
|
} else {
|
|
return ScreenLoading();
|
|
}
|
|
},
|
|
));
|
|
}
|
|
}
|