64 lines
1.6 KiB
Dart
64 lines
1.6 KiB
Dart
import 'dart:convert';
|
|
import 'dart:math';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../drawer/my_drawer.dart';
|
|
import '../preview/preview_grid.dart';
|
|
import '../api/api.dart';
|
|
import '../utils/platform.dart';
|
|
import '../types/video.dart';
|
|
|
|
class ShuffleScreen extends StatefulWidget {
|
|
const ShuffleScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<ShuffleScreen> createState() => _ShuffleScreenState();
|
|
}
|
|
|
|
class _ShuffleScreenState extends State<ShuffleScreen> {
|
|
Future<List<VideoT>> loadData(int nr) async {
|
|
final data = await API.query("video", "getRandomMovies",
|
|
{'Number': nr, 'Seed': Random().nextInt(0x7fffffff)});
|
|
|
|
final d = jsonDecode(data);
|
|
|
|
List<VideoT> dta =
|
|
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
|
|
|
|
return dta;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
double width = MediaQuery.of(context).size.width;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text("Shuffle"),
|
|
),
|
|
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,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
drawer: MyDrawer());
|
|
}
|
|
}
|