From e5212419ae563c91db7523ab0559ff37df7bd091 Mon Sep 17 00:00:00 2001
From: LittleSheep <littlesheep.code@hotmail.com>
Date: Sun, 16 Mar 2025 22:13:19 +0800
Subject: [PATCH] :bug: Fix poll percentage background

---
 lib/widgets/post/post_poll.dart | 101 +++++++++++++++++---------------
 1 file changed, 53 insertions(+), 48 deletions(-)

diff --git a/lib/widgets/post/post_poll.dart b/lib/widgets/post/post_poll.dart
index 695f8d0..d1c05c4 100644
--- a/lib/widgets/post/post_poll.dart
+++ b/lib/widgets/post/post_poll.dart
@@ -80,59 +80,64 @@ class _PostPollState extends State<PostPoll> {
 
   @override
   Widget build(BuildContext context) {
-    return Card(
-      margin: EdgeInsets.zero,
-      child: Column(
-        children: [
-          for (final option in _poll.options)
-            Stack(
-              children: [
-                ClipRRect(
-                  borderRadius: const BorderRadius.all(Radius.circular(8)),
-                  child: Container(
-                    height: 60,
-                    width: MediaQuery.of(context).size.width *
-                        (_poll.metric.byOptionsPercentage[option.id] ?? 0)
-                            .toDouble(),
-                    color: Theme.of(context).colorScheme.surfaceContainerHigh,
-                  ),
-                ),
-                ListTile(
-                  shape: RoundedRectangleBorder(
-                    borderRadius: BorderRadius.circular(8),
-                  ),
-                  minTileHeight: 60,
-                  leading: _answeredChoice == option.id
-                      ? const Icon(Symbols.circle, fill: 1)
-                      : const Icon(Symbols.circle),
-                  title: Text(option.name),
-                  subtitle: Column(
-                    crossAxisAlignment: CrossAxisAlignment.start,
-                    mainAxisSize: MainAxisSize.min,
-                    children: [
-                      Row(
+    return LayoutBuilder(
+      builder: (context, constraints) {
+        return Card(
+          margin: EdgeInsets.zero,
+          child: Column(
+            children: [
+              for (final option in _poll.options)
+                Stack(
+                  children: [
+                    ClipRRect(
+                      borderRadius: const BorderRadius.all(Radius.circular(8)),
+                      child: Container(
+                        height: 60,
+                        width: constraints.maxWidth *
+                            (_poll.metric.byOptionsPercentage[option.id] ?? 0)
+                                .toDouble(),
+                        color:
+                            Theme.of(context).colorScheme.surfaceContainerHigh,
+                      ),
+                    ),
+                    ListTile(
+                      shape: RoundedRectangleBorder(
+                        borderRadius: BorderRadius.circular(8),
+                      ),
+                      minTileHeight: 60,
+                      leading: _answeredChoice == option.id
+                          ? const Icon(Symbols.circle, fill: 1)
+                          : const Icon(Symbols.circle),
+                      title: Text(option.name),
+                      subtitle: Column(
+                        crossAxisAlignment: CrossAxisAlignment.start,
                         mainAxisSize: MainAxisSize.min,
                         children: [
-                          Text(
-                            'pollVotes'
-                                .plural(_poll.metric.byOptions[option.id] ?? 0),
-                          ),
-                          Text(' · ').padding(horizontal: 4),
-                          Text(
-                            '${((_poll.metric.byOptionsPercentage[option.id] ?? 0).toDouble() * 100).toStringAsFixed(2)}%',
+                          Row(
+                            mainAxisSize: MainAxisSize.min,
+                            children: [
+                              Text(
+                                'pollVotes'.plural(
+                                    _poll.metric.byOptions[option.id] ?? 0),
+                              ),
+                              Text(' · ').padding(horizontal: 4),
+                              Text(
+                                '${((_poll.metric.byOptionsPercentage[option.id] ?? 0).toDouble() * 100).toStringAsFixed(2)}%',
+                              ),
+                            ],
                           ),
+                          if (option.description.isNotEmpty)
+                            Text(option.description),
                         ],
                       ),
-                      if (option.description.isNotEmpty)
-                        Text(option.description),
-                    ],
-                  ),
-                  onTap: _isBusy ? null : () => _voteForOption(option),
-                ),
-              ],
-            )
-        ],
-      ),
+                      onTap: _isBusy ? null : () => _voteForOption(option),
+                    ),
+                  ],
+                )
+            ],
+          ),
+        );
+      },
     );
   }
 }