OpenMediacenterMobileFlutter/lib/video_screen/info_view.dart
lukas-heiligenbrunner 9ef317f0ba outsourced lots of api calls to api folder
centered error message when failed loading video feed
display server url on settings page
2022-10-15 20:28:31 +02:00

148 lines
5.3 KiB
Dart

import 'package:flutter/material.dart';
import '../api/actor_api.dart';
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';
import '../types/actor.dart';
class InfoView extends StatefulWidget {
const InfoView({Key? key, required this.videoId}) : super(key: key);
final int videoId;
@override
State<InfoView> createState() => _InfoViewState();
}
class _InfoViewState extends State<InfoView> {
late Future<List<Actor>> _data;
late Future<VideoData> vdata;
@override
void initState() {
super.initState();
setState(() {
_data = loadActorsOfVideo(widget.videoId);
vdata = loadVideoData(widget.videoId);
});
}
@override
void didUpdateWidget(InfoView oldWidget) {
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: Future.wait([_data, vdata]),
builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
if (snapshot.hasError) {
return Text("Error");
} else if (snapshot.hasData) {
final actors = snapshot.data![0] as List<Actor>;
final videoData = snapshot.data![1] as VideoData;
return Padding(
padding: EdgeInsets.only(left: 10, right: 10, top: 60),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
IconButton(
onPressed: () async {
if (await addLike(videoData.movieId))
setState(() {
vdata = loadVideoData(widget.videoId);
});
},
icon: Icon(Icons.thumb_up)),
TextButton(
onPressed: () async {
await showDialog(
context: context,
builder: (context) => AddActorDialog(
movieId: videoData.movieId,
),
);
setState(() {
_data = loadActorsOfVideo(widget.videoId);
});
},
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
? Text("no actors available")
: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: _renderActors(actors),
),
),
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),
),
);
},
),
)
.toList(growable: false),
)
]));
} else {
return ScreenLoading();
}
},
);
}
List<Widget> _renderActors(List<Actor> actors) {
return actors.map((e) => ActorTile(actor: e)).toList(growable: false);
}
}