2021-12-10 10:40:20 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-04-15 07:16:41 +00:00
|
|
|
import 'package:openmediacentermobile/videoscreen.dart';
|
2021-12-10 10:40:20 +00:00
|
|
|
|
2021-12-11 16:17:38 +00:00
|
|
|
import 'api/api.dart';
|
2022-04-15 07:16:41 +00:00
|
|
|
import 'platform.dart';
|
2021-12-11 16:17:38 +00:00
|
|
|
|
|
|
|
class VideoT {
|
2021-12-10 10:40:20 +00:00
|
|
|
int id;
|
2021-12-11 16:17:38 +00:00
|
|
|
String title;
|
|
|
|
double Ratio;
|
2021-12-10 10:40:20 +00:00
|
|
|
|
2021-12-11 16:17:38 +00:00
|
|
|
VideoT(this.title, this.id, this.Ratio);
|
|
|
|
|
|
|
|
factory VideoT.fromJson(dynamic json) {
|
2022-04-15 07:16:41 +00:00
|
|
|
return VideoT(json['MovieName'] as String, json['MovieId'] as int, (json['Ratio'] as num).toDouble());
|
2021-12-11 16:17:38 +00:00
|
|
|
}
|
2021-12-10 10:40:20 +00:00
|
|
|
}
|
|
|
|
|
2021-12-11 16:17:38 +00:00
|
|
|
class PreviewTile extends StatefulWidget {
|
2021-12-10 10:40:20 +00:00
|
|
|
const PreviewTile({Key? key, required this.dta}) : super(key: key);
|
2021-12-11 16:17:38 +00:00
|
|
|
final VideoT dta;
|
|
|
|
|
|
|
|
@override
|
|
|
|
_PreviewTileState createState() => _PreviewTileState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PreviewTileState extends State<PreviewTile> {
|
2022-04-15 07:16:41 +00:00
|
|
|
late Future<Image> _preview;
|
2021-12-10 10:40:20 +00:00
|
|
|
|
2021-12-11 16:17:38 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
2022-04-15 07:16:41 +00:00
|
|
|
_preview = loadData();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Image> loadData() async {
|
|
|
|
final data = await API.query("video", "readThumbnail", {'Movieid': widget.dta.id});
|
|
|
|
|
|
|
|
final img = Image.memory(
|
|
|
|
base64Decode(data.substring(23)),
|
|
|
|
width: double.infinity,
|
|
|
|
fit: BoxFit.fitWidth,
|
|
|
|
);
|
|
|
|
|
|
|
|
// precache image to avoid loading time to render image
|
|
|
|
await precacheImage(img.image, context);
|
|
|
|
|
|
|
|
return img;
|
2021-12-11 16:17:38 +00:00
|
|
|
}
|
2021-12-10 10:40:20 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-04-15 07:16:41 +00:00
|
|
|
return FutureBuilder<Image>(
|
|
|
|
future: _preview, // a previously-obtained Future<String> or null
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<Image> snapshot) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Text("Error");
|
|
|
|
} else if (snapshot.hasData) {
|
|
|
|
return ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(20.0),
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
child: Column(
|
|
|
|
children: [Text(widget.dta.title, style: TextStyle(fontSize: isTV() ? 8 : 12)), snapshot.data!],
|
|
|
|
),
|
|
|
|
color: Colors.green,
|
|
|
|
),
|
|
|
|
Positioned.fill(
|
|
|
|
child: Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => VideoScreen(videoID: widget.dta.id),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Column(children: const <Widget>[
|
|
|
|
SizedBox(height: 100),
|
|
|
|
SizedBox(
|
|
|
|
width: 60,
|
|
|
|
height: 60,
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 16),
|
|
|
|
child: Text('Awaiting result...'),
|
|
|
|
),
|
|
|
|
SizedBox(height: 100),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
},
|
2021-12-10 10:40:20 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|