change sort pairs to be more type safe
This commit is contained in:
parent
46a2f48e3a
commit
bd8da4c2f7
|
@ -11,14 +11,21 @@ import 'bottom_safe.dart';
|
||||||
import 'comment/comment.dart';
|
import 'comment/comment.dart';
|
||||||
import 'post/full_post_store.dart';
|
import 'post/full_post_store.dart';
|
||||||
|
|
||||||
|
class _SortSelection {
|
||||||
|
final IconData icon;
|
||||||
|
final String text;
|
||||||
|
|
||||||
|
const _SortSelection(this.icon, this.text);
|
||||||
|
}
|
||||||
|
|
||||||
/// Manages comments section, sorts them
|
/// Manages comments section, sorts them
|
||||||
class CommentSection extends StatelessWidget {
|
class CommentSection extends StatelessWidget {
|
||||||
static const sortPairs = {
|
static const sortPairs = {
|
||||||
CommentSortType.hot: [Icons.whatshot, L10nStrings.hot],
|
CommentSortType.hot: _SortSelection(Icons.whatshot, L10nStrings.hot),
|
||||||
CommentSortType.new_: [Icons.new_releases, L10nStrings.new_],
|
CommentSortType.new_: _SortSelection(Icons.new_releases, L10nStrings.new_),
|
||||||
CommentSortType.old: [Icons.calendar_today, L10nStrings.old],
|
CommentSortType.old: _SortSelection(Icons.calendar_today, L10nStrings.old),
|
||||||
CommentSortType.top: [Icons.trending_up, L10nStrings.top],
|
CommentSortType.top: _SortSelection(Icons.trending_up, L10nStrings.top),
|
||||||
CommentSortType.chat: [Icons.chat, L10nStrings.chat],
|
CommentSortType.chat: _SortSelection(Icons.chat, L10nStrings.chat),
|
||||||
};
|
};
|
||||||
|
|
||||||
const CommentSection({Key? key}) : super(key: key);
|
const CommentSection({Key? key}) : super(key: key);
|
||||||
|
@ -62,8 +69,8 @@ class CommentSection extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
for (final e in sortPairs.entries)
|
for (final e in sortPairs.entries)
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: Icon(e.value[0] as IconData),
|
leading: Icon(e.value.icon),
|
||||||
title: Text((e.value[1] as String).tr(context)),
|
title: Text((e.value.text).tr(context)),
|
||||||
trailing: store.sorting == e.key
|
trailing: store.sorting == e.key
|
||||||
? const Icon(Icons.check)
|
? const Icon(Icons.check)
|
||||||
: null,
|
: null,
|
||||||
|
@ -78,8 +85,7 @@ class CommentSection extends StatelessWidget {
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text((sortPairs[store.sorting]![1] as String)
|
Text((sortPairs[store.sorting]!.text).tr(context)),
|
||||||
.tr(context)),
|
|
||||||
const Icon(Icons.arrow_drop_down),
|
const Icon(Icons.arrow_drop_down),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue