2022-08-21 20:44:12 +00:00
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
|
|
import 'package:openmediacentermobile/platform.dart';
|
|
|
|
import 'package:openmediacentermobile/preview_tile.dart';
|
|
|
|
|
|
|
|
class PreviewGrid extends StatefulWidget {
|
2022-08-25 20:48:44 +00:00
|
|
|
const PreviewGrid(
|
|
|
|
{Key? key,
|
|
|
|
required this.videoLoader,
|
|
|
|
this.headerBuilder,
|
|
|
|
this.footerBuilder})
|
|
|
|
: super(key: key);
|
2022-08-21 20:44:12 +00:00
|
|
|
|
|
|
|
final Future<List<VideoT>> Function() videoLoader;
|
2022-08-25 20:20:25 +00:00
|
|
|
final Widget Function(_PreviewGridState state)? footerBuilder;
|
|
|
|
final Widget Function(_PreviewGridState state)? headerBuilder;
|
2022-08-21 20:44:12 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<PreviewGrid> createState() => _PreviewGridState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PreviewGridState extends State<PreviewGrid> {
|
|
|
|
late Future<List<VideoT>> _data;
|
|
|
|
Image? _previewImage;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2022-08-25 20:20:25 +00:00
|
|
|
loadData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadData() {
|
|
|
|
setState(() {
|
|
|
|
_data = widget.videoLoader();
|
|
|
|
});
|
2022-08-21 20:44:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-25 17:48:09 +00:00
|
|
|
final double width = MediaQuery.of(context).size.width;
|
2022-08-21 20:44:12 +00:00
|
|
|
|
|
|
|
return FutureBuilder<List<VideoT>>(
|
2022-08-25 20:48:44 +00:00
|
|
|
future: _data,
|
2022-08-21 20:44:12 +00:00
|
|
|
builder: (BuildContext context, AsyncSnapshot<List<VideoT>> snapshot) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Text("Error");
|
|
|
|
} else if (snapshot.hasData) {
|
2022-08-25 20:48:44 +00:00
|
|
|
return _mainGrid(snapshot.data!, width);
|
2022-08-21 20:44:12 +00:00
|
|
|
} else {
|
2022-08-25 20:48:44 +00:00
|
|
|
return _pageLoading();
|
2022-08-21 20:44:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2022-08-25 20:48:44 +00:00
|
|
|
|
|
|
|
Widget _pageLoading() {
|
|
|
|
return Column(children: const <Widget>[
|
|
|
|
SizedBox(
|
|
|
|
width: 60,
|
|
|
|
height: 60,
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 16),
|
|
|
|
child: Text('Awaiting result...'),
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _mainGrid(List<VideoT> data, double width) {
|
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
if (widget.headerBuilder != null) widget.headerBuilder!(this),
|
|
|
|
Expanded(
|
|
|
|
child: MasonryGridView.count(
|
|
|
|
// every tile should be at max 330 pixels long...
|
|
|
|
crossAxisCount: isTV() ? width ~/ 200 : width ~/ 275,
|
|
|
|
// crossAxisCount: isTV() ? width ~/ 200 : width ~/ 330,
|
|
|
|
itemCount: data.length,
|
|
|
|
mainAxisSpacing: 4,
|
|
|
|
crossAxisSpacing: 4,
|
|
|
|
padding: EdgeInsets.all(5),
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return PreviewTile(
|
|
|
|
dta: data[index],
|
|
|
|
onLongPress: (img) {
|
|
|
|
setState(() {
|
|
|
|
_previewImage = img;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onLongPressEnd: () {
|
|
|
|
setState(() {
|
|
|
|
_previewImage = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (widget.footerBuilder != null) widget.footerBuilder!(this),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (_previewImage != null) ..._buildPreviewImage(),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Widget> _buildPreviewImage() {
|
|
|
|
return [
|
|
|
|
BackdropFilter(
|
|
|
|
filter: ImageFilter.blur(
|
|
|
|
sigmaX: 5.0,
|
|
|
|
sigmaY: 5.0,
|
|
|
|
),
|
|
|
|
child: Container(
|
|
|
|
color: Colors.white.withOpacity(0.6),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
child: Center(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 50),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
|
|
child: _previewImage!),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2022-08-21 20:44:12 +00:00
|
|
|
}
|