2020-09-07 22:05:50 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-09-05 23:55:07 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
|
|
|
|
2020-09-07 16:19:28 +02:00
|
|
|
import 'bottom_modal.dart';
|
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// Dropdown filters where you can change sorting or viewing type
|
2020-09-07 22:49:41 +02:00
|
|
|
class PostListOptions extends HookWidget {
|
2020-09-07 20:22:31 +02:00
|
|
|
final void Function(SortType sort) onChange;
|
2020-09-05 23:55:07 +02:00
|
|
|
final SortType defaultSort;
|
2020-09-29 00:35:05 +02:00
|
|
|
final bool styleButton;
|
2020-09-05 23:55:07 +02:00
|
|
|
|
2020-09-07 22:49:41 +02:00
|
|
|
PostListOptions({
|
2020-09-05 23:55:07 +02:00
|
|
|
@required this.onChange,
|
2020-09-29 00:35:05 +02:00
|
|
|
this.styleButton = true,
|
2020-09-05 23:55:07 +02:00
|
|
|
this.defaultSort = SortType.active,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-16 23:22:04 +02:00
|
|
|
final sort = useState(defaultSort);
|
2020-09-05 23:55:07 +02:00
|
|
|
|
|
|
|
void selectSortType(BuildContext context) {
|
|
|
|
showModalBottomSheet(
|
|
|
|
isScrollControlled: true,
|
|
|
|
context: context,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
builder: (context) => BottomModal(
|
|
|
|
title: 'sort by',
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2020-09-16 23:22:04 +02:00
|
|
|
for (final x in SortType.values)
|
2020-09-05 23:55:07 +02:00
|
|
|
RadioListTile<SortType>(
|
|
|
|
value: x,
|
|
|
|
groupValue: sort.value,
|
2020-09-29 00:34:35 +02:00
|
|
|
title: Text(x.value),
|
2020-09-05 23:55:07 +02:00
|
|
|
onChanged: (val) {
|
|
|
|
sort.value = val;
|
|
|
|
onChange(val);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
OutlineButton(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
onPressed: () => selectSortType(context),
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
2020-09-29 00:34:35 +02:00
|
|
|
Text(sort.value.value),
|
2020-09-05 23:55:07 +02:00
|
|
|
const SizedBox(width: 8),
|
|
|
|
Icon(Icons.arrow_drop_down),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Spacer(),
|
2020-09-29 00:35:05 +02:00
|
|
|
if (styleButton)
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.view_stream),
|
2020-09-29 21:05:30 +02:00
|
|
|
// TODO: create compact post and dropdown for selecting
|
2020-09-29 00:35:05 +02:00
|
|
|
onPressed: () => print('TBD'),
|
|
|
|
),
|
2020-09-05 23:55:07 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|