Skip to content

Commit ef67a67

Browse files
committed
compose [nfc]: Pass PageRoot.contextOf to _Banner.buildTrailing
See added dartdoc for motivation. I don't think there's a behavior change here; we don't use the passed BuildContext after an async gap. We'd like to do that soon, though: to show an error dialog on API errors from the edit-message request; such errors will arrive after the banner has disappeared.
1 parent fffc6fc commit ef67a67

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lib/widgets/compose_box.dart

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'color.dart';
2323
import 'dialog.dart';
2424
import 'icons.dart';
2525
import 'inset_shadow.dart';
26+
import 'page.dart';
2627
import 'store.dart';
2728
import 'text.dart';
2829
import 'theme.dart';
@@ -1685,6 +1686,9 @@ class EditMessageComposeBoxController extends ComposeBoxController {
16851686
String? originalRawContent;
16861687
}
16871688

1689+
/// A banner to display over or instead of interactive compose-box content.
1690+
///
1691+
/// Must have a [PageRoot] ancestor.
16881692
abstract class _Banner extends StatelessWidget {
16891693
const _Banner();
16901694

@@ -1701,7 +1705,11 @@ abstract class _Banner extends StatelessWidget {
17011705
/// https://github.com/zulip/zulip-flutter/pull/1432#discussion_r2023907300
17021706
///
17031707
/// To control the element's distance from the end edge, override [padEnd].
1704-
Widget? buildTrailing(BuildContext context);
1708+
///
1709+
/// The passed [BuildContext] will be the result of [PageRoot.contextOf],
1710+
/// so it's expected to remain mounted until the whole page disappears,
1711+
/// which may be long after the banner disappears.
1712+
Widget? buildTrailing(BuildContext pageContext);
17051713

17061714
/// Whether to apply `end: 8` in [SafeArea.minimum].
17071715
///
@@ -1720,7 +1728,7 @@ abstract class _Banner extends StatelessWidget {
17201728
color: getLabelColor(designVariables),
17211729
).merge(weightVariableTextStyle(context, wght: 600));
17221730

1723-
final trailing = buildTrailing(context);
1731+
final trailing = buildTrailing(PageRoot.contextOf(context));
17241732
return DecoratedBox(
17251733
decoration: BoxDecoration(
17261734
color: getBackgroundColor(designVariables)),
@@ -1766,7 +1774,7 @@ class _ErrorBanner extends _Banner {
17661774
designVariables.bannerBgIntDanger;
17671775

17681776
@override
1769-
Widget? buildTrailing(context) {
1777+
Widget? buildTrailing(pageContext) {
17701778
// An "x" button can go here.
17711779
// 24px square with 8px touchable padding in all directions?
17721780
// and `bool get padEnd => false`; see Figma:
@@ -1792,17 +1800,17 @@ class _EditMessageBanner extends _Banner {
17921800
Color getBackgroundColor(DesignVariables designVariables) =>
17931801
designVariables.bannerBgIntInfo;
17941802

1795-
void _handleTapSave (BuildContext context) {
1796-
final store = PerAccountStoreWidget.of(context);
1803+
void _handleTapSave (BuildContext pageContext) {
1804+
final store = PerAccountStoreWidget.of(pageContext);
17971805
final controller = composeBoxState.controller;
17981806
if (controller is! EditMessageComposeBoxController) return; // TODO(log)
1799-
final zulipLocalizations = ZulipLocalizations.of(context);
1807+
final zulipLocalizations = ZulipLocalizations.of(pageContext);
18001808

18011809
if (controller.content.hasValidationErrors.value) {
18021810
final validationErrorMessages =
18031811
controller.content.validationErrors.map((error) =>
18041812
error.message(zulipLocalizations));
1805-
showErrorDialog(context: context,
1813+
showErrorDialog(context: pageContext,
18061814
title: zulipLocalizations.errorMessageEditNotSaved,
18071815
message: validationErrorMessages.join('\n\n'));
18081816
return;
@@ -1825,16 +1833,16 @@ class _EditMessageBanner extends _Banner {
18251833
}
18261834

18271835
@override
1828-
Widget buildTrailing(context) {
1829-
final zulipLocalizations = ZulipLocalizations.of(context);
1836+
Widget buildTrailing(pageContext) {
1837+
final zulipLocalizations = ZulipLocalizations.of(pageContext);
18301838
return Row(mainAxisSize: MainAxisSize.min, spacing: 8, children: [
18311839
ZulipWebUiKitButton(label: zulipLocalizations.composeBoxBannerButtonCancel,
18321840
onPressed: composeBoxState.endEditInteraction),
18331841
// TODO(#1481) disabled appearance when there are validation errors
18341842
// or the original raw content hasn't loaded yet
18351843
ZulipWebUiKitButton(label: zulipLocalizations.composeBoxBannerButtonSave,
18361844
attention: ZulipWebUiKitButtonAttention.high,
1837-
onPressed: () => _handleTapSave(context)),
1845+
onPressed: () => _handleTapSave(pageContext)),
18381846
]);
18391847
}
18401848
}

0 commit comments

Comments
 (0)