🐛 Fix poll feedback, close #224
This commit is contained in:
@@ -56,34 +56,33 @@ class PollFeedbackSheet extends HookConsumerWidget {
|
|||||||
return SheetScaffold(
|
return SheetScaffold(
|
||||||
titleText: title ?? 'Poll feedback',
|
titleText: title ?? 'Poll feedback',
|
||||||
child: poll.when(
|
child: poll.when(
|
||||||
data:
|
data: (data) => CustomScrollView(
|
||||||
(data) => CustomScrollView(
|
slivers: [
|
||||||
slivers: [
|
SliverToBoxAdapter(child: _PollHeader(poll: data)),
|
||||||
SliverToBoxAdapter(child: _PollHeader(poll: data)),
|
SliverToBoxAdapter(child: const Divider(height: 1)),
|
||||||
SliverToBoxAdapter(child: const Divider(height: 1)),
|
SliverGap(4),
|
||||||
SliverGap(4),
|
PaginationList(
|
||||||
PaginationList(
|
provider: provider,
|
||||||
provider: provider,
|
notifier: provider.notifier,
|
||||||
notifier: provider.notifier,
|
isSliver: true,
|
||||||
isSliver: true,
|
isRefreshable: false,
|
||||||
itemBuilder: (context, index, answer) {
|
itemBuilder: (context, index, answer) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
_PollAnswerTile(answer: answer, poll: data),
|
_PollAnswerTile(answer: answer, poll: data),
|
||||||
if (index < (ref.read(provider).value?.length ?? 0) - 1)
|
if (index < (ref.read(provider).value?.length ?? 0) - 1)
|
||||||
const Divider(height: 1).padding(vertical: 4),
|
const Divider(height: 1).padding(vertical: 4),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
|
||||||
SliverGap(4 + MediaQuery.of(context).padding.bottom),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
error:
|
|
||||||
(err, _) => ResponseErrorWidget(
|
|
||||||
error: err,
|
|
||||||
onRetry: () => ref.invalidate(pollWithStatsProvider(pollId)),
|
|
||||||
),
|
),
|
||||||
|
SliverGap(4 + MediaQuery.of(context).padding.bottom),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
error: (err, _) => ResponseErrorWidget(
|
||||||
|
error: err,
|
||||||
|
onRetry: () => ref.invalidate(pollWithStatsProvider(pollId)),
|
||||||
|
),
|
||||||
loading: () => ResponseLoadingWidget(),
|
loading: () => ResponseLoadingWidget(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -120,20 +119,19 @@ class _PollHeader extends StatelessWidget {
|
|||||||
ExpansionTile(
|
ExpansionTile(
|
||||||
title: Text('pollQuestions').tr().fontSize(17).bold(),
|
title: Text('pollQuestions').tr().fontSize(17).bold(),
|
||||||
tilePadding: EdgeInsets.symmetric(horizontal: 20),
|
tilePadding: EdgeInsets.symmetric(horizontal: 20),
|
||||||
children:
|
children: poll.questions
|
||||||
poll.questions
|
.map(
|
||||||
.map(
|
(q) => Column(
|
||||||
(q) => Column(
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
children: [
|
||||||
children: [
|
if (q.title.isNotEmpty) Text(q.title).bold(),
|
||||||
if (q.title.isNotEmpty) Text(q.title).bold(),
|
if (q.description?.isNotEmpty ?? false)
|
||||||
if (q.description?.isNotEmpty ?? false)
|
Text(q.description!),
|
||||||
Text(q.description!),
|
PollStatsWidget(question: q, stats: poll.stats),
|
||||||
PollStatsWidget(question: q, stats: poll.stats),
|
],
|
||||||
],
|
).padding(horizontal: 20, top: 8, bottom: 16),
|
||||||
).padding(horizontal: 20, top: 8, bottom: 16),
|
)
|
||||||
)
|
.toList(),
|
||||||
.toList(),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -165,14 +163,13 @@ class _PollAnswerTile extends StatelessWidget {
|
|||||||
if (val is List) {
|
if (val is List) {
|
||||||
final ids = val.whereType<String>().toList();
|
final ids = val.whereType<String>().toList();
|
||||||
if (ids.isEmpty) return '—';
|
if (ids.isEmpty) return '—';
|
||||||
final labels =
|
final labels = ids.map((id) {
|
||||||
ids.map((id) {
|
final opt = q.options?.firstWhere(
|
||||||
final opt = q.options?.firstWhere(
|
(o) => o.id == id,
|
||||||
(o) => o.id == id,
|
orElse: () => SnPollOption(id: id, label: '#$id', order: 0),
|
||||||
orElse: () => SnPollOption(id: id, label: '#$id', order: 0),
|
);
|
||||||
);
|
return opt?.label ?? '#$id';
|
||||||
return opt?.label ?? '#$id';
|
}).toList();
|
||||||
}).toList();
|
|
||||||
return labels.join(', ');
|
return labels.join(', ');
|
||||||
}
|
}
|
||||||
return '—';
|
return '—';
|
||||||
@@ -197,10 +194,9 @@ class _PollAnswerTile extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Submit date/time (title)
|
// Submit date/time (title)
|
||||||
final submitText =
|
final submitText = answer.account == null
|
||||||
answer.account == null
|
? answer.createdAt.formatSystem()
|
||||||
? answer.createdAt.formatSystem()
|
: '${answer.account!.nick} · ${answer.createdAt.formatSystem()}';
|
||||||
: '${answer.account!.nick} · ${answer.createdAt.formatSystem()}';
|
|
||||||
|
|
||||||
// Compose content from poll questions if provided, otherwise fallback to joined key-values
|
// Compose content from poll questions if provided, otherwise fallback to joined key-values
|
||||||
String content;
|
String content;
|
||||||
@@ -237,18 +233,17 @@ class _PollAnswerTile extends StatelessWidget {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 20),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 20),
|
||||||
isThreeLine: true,
|
isThreeLine: true,
|
||||||
leading:
|
leading: answer.account == null
|
||||||
answer.account == null
|
? const CircleAvatar(
|
||||||
? const CircleAvatar(
|
radius: 16,
|
||||||
radius: 16,
|
child: Icon(Icons.how_to_vote, size: 16),
|
||||||
child: Icon(Icons.how_to_vote, size: 16),
|
)
|
||||||
)
|
: AccountPfcGestureDetector(
|
||||||
: AccountPfcGestureDetector(
|
uname: answer.account!.name,
|
||||||
uname: answer.account!.name,
|
child: ProfilePictureWidget(
|
||||||
child: ProfilePictureWidget(
|
file: answer.account!.profile.picture,
|
||||||
file: answer.account!.profile.picture,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
title: Text(submitText),
|
title: Text(submitText),
|
||||||
subtitle: Text(content),
|
subtitle: Text(content),
|
||||||
trailing: null,
|
trailing: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user