2021-12-10 10:40:20 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-04-15 18:19:09 +00:00
|
|
|
import 'package:openmediacentermobile/videoscreen_desktop.dart'
|
|
|
|
if (dart.library.html) 'package:openmediacentermobile/videoscreen_web.dart'
|
|
|
|
if (dart.library.io) 'package:openmediacentermobile/videoscreen_desktop.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
|
|
|
|
2022-04-15 19:57:15 +00:00
|
|
|
// todo put this type in sperate class!
|
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;
|
2022-08-25 17:48:09 +00:00
|
|
|
double ratio;
|
2021-12-10 10:40:20 +00:00
|
|
|
|
2022-08-25 17:48:09 +00:00
|
|
|
VideoT(this.title, this.id, this.ratio);
|
2021-12-11 16:17:38 +00:00
|
|
|
|
|
|
|
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 {
|
2022-08-21 20:44:12 +00:00
|
|
|
const PreviewTile({Key? key, required this.dta, this.onLongPress, this.onLongPressEnd}) : super(key: key);
|
2021-12-11 16:17:38 +00:00
|
|
|
final VideoT dta;
|
2022-08-21 20:44:12 +00:00
|
|
|
final Function(Image img)? onLongPress;
|
|
|
|
final Function? onLongPressEnd;
|
2021-12-11 16:17:38 +00:00
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
|
2022-04-15 19:57:15 +00:00
|
|
|
@override
|
|
|
|
void didUpdateWidget(PreviewTile oldWidget) {
|
|
|
|
super.didUpdateWidget(oldWidget);
|
|
|
|
|
|
|
|
if (oldWidget.dta != widget.dta) {
|
|
|
|
setState(() {
|
|
|
|
_preview = loadData();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-15 07:16:41 +00:00
|
|
|
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(
|
2022-08-21 20:44:12 +00:00
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
widget.dta.title,
|
|
|
|
style: TextStyle(fontSize: isTV() ? 8 : 10.5),
|
|
|
|
overflow: TextOverflow.clip,
|
|
|
|
maxLines: 1,
|
|
|
|
),
|
|
|
|
snapshot.data!
|
|
|
|
],
|
2022-04-15 07:16:41 +00:00
|
|
|
),
|
2022-08-21 20:44:12 +00:00
|
|
|
color: Color(0xFF6CE56F),
|
2022-04-15 07:16:41 +00:00
|
|
|
),
|
|
|
|
Positioned.fill(
|
|
|
|
child: Material(
|
|
|
|
color: Colors.transparent,
|
2022-08-21 20:44:12 +00:00
|
|
|
child: GestureDetector(
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
onLongPress: () {
|
|
|
|
if (widget.onLongPress != null) widget.onLongPress!(snapshot.data!);
|
2022-04-15 07:16:41 +00:00
|
|
|
},
|
2022-08-21 20:44:12 +00:00
|
|
|
onLongPressEnd: (details) {
|
|
|
|
if (widget.onLongPressEnd != null) widget.onLongPressEnd!();
|
|
|
|
},
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2022-08-25 17:48:09 +00:00
|
|
|
builder: (context) => VideoScreen(metaData: widget.dta),
|
2022-08-21 20:44:12 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-04-15 07:16:41 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} 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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|