lemmur-app-android/lib/widgets/post/post_voting.dart

54 lines
1.6 KiB
Dart
Raw Normal View History

2021-09-11 01:04:15 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:lemmy_api_client/v3.dart';
import '../../hooks/logged_in_action.dart';
import '../../hooks/stores.dart';
import '../../stores/config_store.dart';
2021-09-11 01:04:15 +02:00
import '../../util/intl.dart';
import '../../util/observer_consumers.dart';
import 'post_store.dart';
class PostVoting extends HookWidget {
const PostVoting();
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final showScores = useStore((ConfigStore store) => store.showScores);
2021-09-11 01:04:15 +02:00
final loggedInAction = useLoggedInAction(context
.select<PostStore, String>((store) => store.postView.instanceHost));
return ObserverBuilder<PostStore>(builder: (context, store) {
return Row(
children: [
IconButton(
icon: Icon(
Icons.arrow_upward,
color: store.postView.myVote == VoteType.up
? theme.colorScheme.secondary
: null,
),
onPressed: loggedInAction(store.upVote),
),
if (store.votingState.isLoading)
2021-09-11 01:04:15 +02:00
const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator.adaptive(),
)
2021-09-11 01:04:15 +02:00
else if (showScores)
Text(compactNumber(store.postView.counts.score)),
2021-09-11 01:04:15 +02:00
IconButton(
icon: Icon(
Icons.arrow_downward,
color: store.postView.myVote == VoteType.down ? Colors.red : null,
),
onPressed: loggedInAction(store.downVote),
),
],
);
});
}
}