OpenMediacenterMobileFlutter/lib/video_feed.dart

52 lines
1.2 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:openmediacentermobile/api/api.dart';
import 'log/log.dart';
import 'preview_tile.dart';
class VideoFeed extends StatefulWidget {
const VideoFeed({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return VideoFeedState();
}
}
class VideoFeedState extends State<VideoFeed> {
List<VideoT> _vids = [];
@override
void initState() {
super.initState();
API.query("video", "getMovies", {'Tag': 1, 'Sort': 0}).then((value) {
final d = jsonDecode(value);
List<VideoT> dta =
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
setState(() {
_vids = dta;
});
});
}
@override
Widget build(BuildContext context) {
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.width /
MediaQuery.of(context).size.height,
crossAxisSpacing: 10),
itemCount: _vids.length,
itemBuilder: (context, index) {
Log.d("item $index built!");
return PreviewTile(dta: _vids[index]);
});
}
}