import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:openmediacentermobile/screen_loading.dart'; import 'package:openmediacentermobile/preview/tag_tile.dart'; import 'package:openmediacentermobile/types/video_data.dart'; import 'package:openmediacentermobile/preview/actor_tile.dart'; import '../api/api.dart'; import '../log/log.dart'; import '../types/actor.dart'; class InfoView extends StatefulWidget { const InfoView({Key? key, required this.vdata}) : super(key: key); final VideoData vdata; @override State createState() => _InfoViewState(); } class _InfoViewState extends State { late Future> _data; @override void initState() { setState(() { _data = loadData(); }); super.initState(); } Future> loadData() async { final data = await API .query("actor", "getActorsOfVideo", {'MovieId': widget.vdata.movieId}); if (data == 'null') { return []; } final d = jsonDecode(data); List dta = (d as List).map((e) => Actor.fromJson(e)).toList(); return dta; } @override Widget build(BuildContext context) { return FutureBuilder( future: _data, builder: (context, AsyncSnapshot> snapshot) { if (snapshot.hasError) { return Text("Error"); } else if (snapshot.hasData) { final actors = snapshot.data; return Padding( padding: EdgeInsets.only(left: 10, right: 10, top: 60), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text("Likes: ${widget.vdata.likes}"), IconButton( onPressed: () async { final data = await API.query("video", "addLike", {'MovieId': widget.vdata.movieId}); final d = jsonDecode(data); if (d["result"] != 'success') { Log.w(d); } // bit hacky but it works widget.vdata.likes += 1; }, icon: Icon(Icons.thumb_up)), Text("Quality: ${widget.vdata.quality}"), Text("Length: ${widget.vdata.length}sec"), Text("Actors:"), actors?.isEmpty ?? true ? Text("no actors available") : Row( children: _renderActors(snapshot.data!), ), Text("Tags:"), Row( children: widget.vdata.tags .map((e) => TagTile(tag: e)) .toList(growable: false), ) ])); } else { return ScreenLoading(); } }, ); } List _renderActors(List actors) { return actors.map((e) => ActorTile(actor: e)).toList(growable: false); } }