import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:openmediacentermobile/DrawerPage.dart'; import '../api/api.dart'; import '../preview/preview_grid.dart'; import '../types/tag.dart'; import '../types/video.dart'; enum FilterTypes { DATE, LIKES, RANDOM, NAMES, LENGTH } class VideoFeed extends StatefulWidget { const VideoFeed({Key? key, this.tag}) : super(key: key); final Tag? tag; @override State createState() { return VideoFeedState(); } } class VideoFeedState extends State { FilterTypes filterSelection = FilterTypes.DATE; Key _refreshKey = UniqueKey(); Future> loadData() async { final data = await API.query("video", "getMovies", {'Tag': widget.tag?.tagId ?? 1, 'Sort': filterSelection.index}); final d = jsonDecode(data); List dta = (d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList(); return dta; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.tag?.tagName ?? "OpenMediaCenter"), actions: [ PopupMenuButton( // add icon, by default "3 dot" icon icon: Icon(Icons.filter_alt), initialValue: filterSelection, itemBuilder: (context) { return [ PopupMenuItem( value: FilterTypes.DATE, child: Text("Date"), ), PopupMenuItem( value: FilterTypes.LIKES, child: Text("Likes"), ), PopupMenuItem( value: FilterTypes.RANDOM, child: Text("Random"), ), PopupMenuItem( value: FilterTypes.NAMES, child: Text("Names"), ), PopupMenuItem( value: FilterTypes.LENGTH, child: Text("Length"), ), ]; }, onSelected: (FilterTypes t) { setState(() { filterSelection = t; _refreshKey = UniqueKey(); }); }), ], ), body: PreviewGrid( key: _refreshKey, videoLoader: () => loadData(), ), drawer: widget.tag == null ? MyDrawer() : null); } }