OpenMediacenterMobileFlutter/lib/shufflescreen.dart

58 lines
1.4 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'dart:math';
import 'package:flutter/material.dart';
2022-08-25 20:20:25 +00:00
import 'package:openmediacentermobile/preview_grid.dart';
import 'preview_tile.dart';
import 'api/api.dart';
import 'platform.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;
2022-08-25 20:20:25 +00:00
return PreviewGrid(
videoLoader: () {
2022-08-26 21:39:52 +00:00
return loadData((isTV() ? width ~/ 200 : width ~/ 275) * 2);
},
2022-08-25 20:20:25 +00:00
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,
),
],
),
);
}
}