2022-04-15 19:57:15 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-08-30 21:37:24 +00:00
|
|
|
import '../drawer/my_drawer.dart';
|
2022-08-28 20:51:12 +00:00
|
|
|
import '../preview/preview_grid.dart';
|
2022-08-28 16:48:53 +00:00
|
|
|
import '../api/api.dart';
|
2022-08-30 21:37:24 +00:00
|
|
|
import '../utils/platform.dart';
|
2022-08-28 20:51:12 +00:00
|
|
|
import '../types/video.dart';
|
2022-04-15 19:57:15 +00:00
|
|
|
|
|
|
|
class ShuffleScreen extends StatefulWidget {
|
|
|
|
const ShuffleScreen({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<ShuffleScreen> createState() => _ShuffleScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ShuffleScreenState extends State<ShuffleScreen> {
|
2022-08-25 17:48:09 +00:00
|
|
|
Future<List<VideoT>> loadData(int nr) async {
|
2022-08-25 20:48:44 +00:00
|
|
|
final data = await API.query("video", "getRandomMovies",
|
|
|
|
{'Number': nr, 'Seed': Random().nextInt(0x7fffffff)});
|
2022-04-15 19:57:15 +00:00
|
|
|
|
|
|
|
final d = jsonDecode(data);
|
|
|
|
|
2022-08-25 20:48:44 +00:00
|
|
|
List<VideoT> dta =
|
|
|
|
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
|
2022-04-15 19:57:15 +00:00
|
|
|
|
|
|
|
return dta;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
double width = MediaQuery.of(context).size.width;
|
2022-08-29 15:16:51 +00:00
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-08-30 09:57:50 +00:00
|
|
|
title: Text("Shuffle"),
|
2022-08-29 15:16:51 +00:00
|
|
|
),
|
|
|
|
body: PreviewGrid(
|
|
|
|
videoLoader: () {
|
|
|
|
return loadData((isTV() ? width ~/ 200 : width ~/ 275) * 2);
|
|
|
|
},
|
|
|
|
footerBuilder: (state) => Column(
|
|
|
|
children: [
|
|
|
|
const SizedBox(
|
|
|
|
height: 25,
|
|
|
|
),
|
|
|
|
TextButton.icon(
|
|
|
|
onPressed: () {
|
|
|
|
state.loadData();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.update),
|
|
|
|
label: const Text("Shuffle"),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 25,
|
|
|
|
),
|
|
|
|
],
|
2022-08-25 20:20:25 +00:00
|
|
|
),
|
2022-08-29 15:16:51 +00:00
|
|
|
),
|
|
|
|
drawer: MyDrawer());
|
2022-04-15 19:57:15 +00:00
|
|
|
}
|
|
|
|
}
|