2021-12-11 16:17:38 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2021-12-10 10:40:20 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-12-11 16:17:38 +00:00
|
|
|
import 'package:openmediacentermobile/api/api.dart';
|
2021-12-10 10:40:20 +00:00
|
|
|
|
2021-12-11 12:33:46 +00:00
|
|
|
import 'log/log.dart';
|
2022-04-15 07:16:41 +00:00
|
|
|
import 'platform.dart';
|
2021-12-10 10:40:20 +00:00
|
|
|
import 'preview_tile.dart';
|
2022-04-15 07:16:41 +00:00
|
|
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
2021-12-10 10:40:20 +00:00
|
|
|
|
2021-12-11 16:17:38 +00:00
|
|
|
class VideoFeed extends StatefulWidget {
|
|
|
|
const VideoFeed({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return VideoFeedState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class VideoFeedState extends State<VideoFeed> {
|
2022-04-15 07:16:41 +00:00
|
|
|
late Future<List<VideoT>> _data;
|
|
|
|
|
|
|
|
Future<List<VideoT>> loadData() async {
|
|
|
|
final data = await API.query("video", "getMovies", {'Tag': 1, 'Sort': 0});
|
|
|
|
|
|
|
|
final d = jsonDecode(data);
|
|
|
|
|
|
|
|
List<VideoT> dta = (d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
|
|
|
|
|
|
|
|
return dta;
|
|
|
|
}
|
2021-12-11 16:17:38 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2021-12-10 10:40:20 +00:00
|
|
|
|
2022-04-15 07:16:41 +00:00
|
|
|
_data = loadData();
|
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
|
|
|
double width = MediaQuery.of(context).size.width;
|
|
|
|
Log.d(width);
|
|
|
|
|
|
|
|
return FutureBuilder<List<VideoT>>(
|
|
|
|
future: _data, // a previously-obtained Future<String> or null
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<List<VideoT>> snapshot) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Text("Error");
|
|
|
|
} else if (snapshot.hasData) {
|
|
|
|
return MasonryGridView.count(
|
|
|
|
// every tile should be at max 330 pixels long...
|
|
|
|
crossAxisCount: isTV() ? width ~/ 200 : width ~/ 330,
|
|
|
|
mainAxisSpacing: 4,
|
|
|
|
crossAxisSpacing: 4,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return PreviewTile(dta: snapshot.data![index]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Column(children: const <Widget>[
|
|
|
|
SizedBox(
|
|
|
|
width: 60,
|
|
|
|
height: 60,
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 16),
|
|
|
|
child: Text('Awaiting result...'),
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-12-10 10:40:20 +00:00
|
|
|
}
|
|
|
|
}
|