Skip to content

Commit 779fb4e

Browse files
committed
action_sheet [nfc]: Factor out findMessageListPage on button widget
1 parent 753a9b4 commit 779fb4e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/widgets/action_sheet.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import '../model/internal_link.dart';
1313
import '../model/narrow.dart';
1414
import 'actions.dart';
1515
import 'clipboard.dart';
16-
import 'compose_box.dart';
1716
import 'dialog.dart';
1817
import 'icons.dart';
1918
import 'inset_shadow.dart';
@@ -105,6 +104,16 @@ abstract class MessageActionSheetMenuItemButton extends StatelessWidget {
105104
final Message message;
106105
final BuildContext messageListContext;
107106

107+
/// The [MessageListPageState] this action sheet was triggered from.
108+
///
109+
/// Uses the inefficient [BuildContext.findAncestorStateOfType];
110+
/// don't call this in a build method.
111+
MessageListPageState findMessageListPage() {
112+
assert(messageListContext.mounted,
113+
'findMessageListPage should be called only when messageListContext is known to still be mounted');
114+
return MessageListPage.ancestorOf(messageListContext);
115+
}
116+
108117
@override
109118
Widget build(BuildContext context) {
110119
final designVariables = DesignVariables.of(context);
@@ -315,8 +324,7 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
315324
// This will be null only if the compose box disappeared after the
316325
// message action sheet opened, and before "Quote and reply" was pressed.
317326
// Currently a compose box can't ever disappear, so this is impossible.
318-
ComposeBoxController composeBoxController =
319-
MessageListPage.ancestorOf(messageListContext).composeBoxController!;
327+
var composeBoxController = findMessageListPage().composeBoxController!;
320328
final topicController = composeBoxController.topicController;
321329
if (
322330
topicController != null
@@ -341,8 +349,7 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
341349
// This will be null only if the compose box disappeared during the
342350
// quotation request. Currently a compose box can't ever disappear,
343351
// so this is impossible.
344-
composeBoxController =
345-
MessageListPage.ancestorOf(messageListContext).composeBoxController!;
352+
composeBoxController = findMessageListPage().composeBoxController!;
346353
composeBoxController.contentController
347354
.registerQuoteAndReplyEnd(PerAccountStoreWidget.of(messageListContext), tag,
348355
message: message,

0 commit comments

Comments
 (0)