2022-08-27 17:33:28 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-15 18:28:31 +00:00
|
|
|
import '../api/actor_api.dart';
|
2022-08-30 21:25:21 +00:00
|
|
|
import '../api/video_api.dart';
|
|
|
|
import '../dialog/add_actor_dialog.dart';
|
|
|
|
import '../dialog/add_tag_dialog.dart';
|
|
|
|
import '../navigation/video_feed.dart';
|
|
|
|
import '../screen_loading.dart';
|
|
|
|
import '../types/video_data.dart';
|
|
|
|
import '../preview/actor_tile.dart';
|
2022-08-28 16:48:53 +00:00
|
|
|
import '../types/actor.dart';
|
2022-08-27 17:33:28 +00:00
|
|
|
|
2022-08-28 20:51:12 +00:00
|
|
|
class InfoView extends StatefulWidget {
|
2022-08-30 21:25:21 +00:00
|
|
|
const InfoView({Key? key, required this.videoId}) : super(key: key);
|
|
|
|
final int videoId;
|
2022-08-27 17:33:28 +00:00
|
|
|
|
|
|
|
@override
|
2022-08-28 20:51:12 +00:00
|
|
|
State<InfoView> createState() => _InfoViewState();
|
2022-08-27 17:33:28 +00:00
|
|
|
}
|
|
|
|
|
2022-08-28 20:51:12 +00:00
|
|
|
class _InfoViewState extends State<InfoView> {
|
2022-08-27 17:33:28 +00:00
|
|
|
late Future<List<Actor>> _data;
|
2022-08-30 21:25:21 +00:00
|
|
|
late Future<VideoData> vdata;
|
2022-08-27 17:33:28 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2022-08-30 21:25:21 +00:00
|
|
|
super.initState();
|
2022-08-27 17:33:28 +00:00
|
|
|
setState(() {
|
2022-10-15 18:28:31 +00:00
|
|
|
_data = loadActorsOfVideo(widget.videoId);
|
2022-08-30 21:25:21 +00:00
|
|
|
vdata = loadVideoData(widget.videoId);
|
2022-08-27 17:33:28 +00:00
|
|
|
});
|
2022-08-30 21:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didUpdateWidget(InfoView oldWidget) {
|
|
|
|
super.didUpdateWidget(oldWidget);
|
2022-08-27 17:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder(
|
2022-08-30 21:25:21 +00:00
|
|
|
future: Future.wait([_data, vdata]),
|
|
|
|
builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
|
2022-08-27 17:33:28 +00:00
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Text("Error");
|
|
|
|
} else if (snapshot.hasData) {
|
2022-08-30 21:25:21 +00:00
|
|
|
final actors = snapshot.data![0] as List<Actor>;
|
|
|
|
final videoData = snapshot.data![1] as VideoData;
|
2022-08-28 16:48:53 +00:00
|
|
|
return Padding(
|
2022-08-29 15:16:51 +00:00
|
|
|
padding: EdgeInsets.only(left: 10, right: 10, top: 60),
|
2022-08-28 16:48:53 +00:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-08-30 21:25:21 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () async {
|
2022-10-15 18:28:31 +00:00
|
|
|
if (await addLike(videoData.movieId))
|
|
|
|
setState(() {
|
|
|
|
vdata = loadVideoData(widget.videoId);
|
|
|
|
});
|
2022-08-30 21:25:21 +00:00
|
|
|
},
|
|
|
|
icon: Icon(Icons.thumb_up)),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AddActorDialog(
|
|
|
|
movieId: videoData.movieId,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
setState(() {
|
2022-10-15 18:28:31 +00:00
|
|
|
_data = loadActorsOfVideo(widget.videoId);
|
2022-08-30 21:25:21 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Text("Add Actor"),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AddTagDialog(
|
|
|
|
movieId: videoData.movieId,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
setState(() {
|
|
|
|
vdata = loadVideoData(widget.videoId);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Text("Add Tag"),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"General info:",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
Text("Likes: ${videoData.likes}"),
|
|
|
|
Text("Quality: ${videoData.quality}"),
|
|
|
|
Text("Length: ${videoData.length}sec"),
|
|
|
|
Text("Actors:",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold)),
|
|
|
|
actors.isEmpty
|
2022-08-28 16:48:53 +00:00
|
|
|
? Text("no actors available")
|
2022-08-30 21:25:21 +00:00
|
|
|
: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: Row(
|
|
|
|
children: _renderActors(actors),
|
|
|
|
),
|
2022-08-28 16:48:53 +00:00
|
|
|
),
|
2022-08-30 21:25:21 +00:00
|
|
|
Text("Tags:",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold)),
|
|
|
|
SizedBox(
|
|
|
|
height: 5,
|
|
|
|
),
|
|
|
|
Wrap(
|
|
|
|
spacing: 4,
|
|
|
|
runSpacing: 4,
|
|
|
|
children: videoData.tags
|
|
|
|
.map(
|
|
|
|
(e) => ActionChip(
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).secondaryHeaderColor,
|
|
|
|
label: Text(e.tagName),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => VideoFeed(tag: e),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
2022-08-28 16:48:53 +00:00
|
|
|
.toList(growable: false),
|
|
|
|
)
|
|
|
|
]));
|
2022-08-27 17:33:28 +00:00
|
|
|
} else {
|
|
|
|
return ScreenLoading();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Widget> _renderActors(List<Actor> actors) {
|
2022-08-28 16:48:53 +00:00
|
|
|
return actors.map((e) => ActorTile(actor: e)).toList(growable: false);
|
2022-08-27 17:33:28 +00:00
|
|
|
}
|
|
|
|
}
|