@@ -23,6 +23,7 @@ import 'color.dart';
23
23
import 'dialog.dart' ;
24
24
import 'icons.dart' ;
25
25
import 'inset_shadow.dart' ;
26
+ import 'page.dart' ;
26
27
import 'store.dart' ;
27
28
import 'text.dart' ;
28
29
import 'theme.dart' ;
@@ -1685,6 +1686,9 @@ class EditMessageComposeBoxController extends ComposeBoxController {
1685
1686
String ? originalRawContent;
1686
1687
}
1687
1688
1689
+ /// A banner to display over or instead of interactive compose-box content.
1690
+ ///
1691
+ /// Must have a [PageRoot] ancestor.
1688
1692
abstract class _Banner extends StatelessWidget {
1689
1693
const _Banner ();
1690
1694
@@ -1701,7 +1705,11 @@ abstract class _Banner extends StatelessWidget {
1701
1705
/// https://github.com/zulip/zulip-flutter/pull/1432#discussion_r2023907300
1702
1706
///
1703
1707
/// 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);
1705
1713
1706
1714
/// Whether to apply `end: 8` in [SafeArea.minimum] .
1707
1715
///
@@ -1720,7 +1728,7 @@ abstract class _Banner extends StatelessWidget {
1720
1728
color: getLabelColor (designVariables),
1721
1729
).merge (weightVariableTextStyle (context, wght: 600 ));
1722
1730
1723
- final trailing = buildTrailing (context);
1731
+ final trailing = buildTrailing (PageRoot . contextOf ( context) );
1724
1732
return DecoratedBox (
1725
1733
decoration: BoxDecoration (
1726
1734
color: getBackgroundColor (designVariables)),
@@ -1766,7 +1774,7 @@ class _ErrorBanner extends _Banner {
1766
1774
designVariables.bannerBgIntDanger;
1767
1775
1768
1776
@override
1769
- Widget ? buildTrailing (context ) {
1777
+ Widget ? buildTrailing (pageContext ) {
1770
1778
// An "x" button can go here.
1771
1779
// 24px square with 8px touchable padding in all directions?
1772
1780
// and `bool get padEnd => false`; see Figma:
@@ -1792,17 +1800,17 @@ class _EditMessageBanner extends _Banner {
1792
1800
Color getBackgroundColor (DesignVariables designVariables) =>
1793
1801
designVariables.bannerBgIntInfo;
1794
1802
1795
- void _handleTapSave (BuildContext context ) {
1796
- final store = PerAccountStoreWidget .of (context );
1803
+ void _handleTapSave (BuildContext pageContext ) {
1804
+ final store = PerAccountStoreWidget .of (pageContext );
1797
1805
final controller = composeBoxState.controller;
1798
1806
if (controller is ! EditMessageComposeBoxController ) return ; // TODO(log)
1799
- final zulipLocalizations = ZulipLocalizations .of (context );
1807
+ final zulipLocalizations = ZulipLocalizations .of (pageContext );
1800
1808
1801
1809
if (controller.content.hasValidationErrors.value) {
1802
1810
final validationErrorMessages =
1803
1811
controller.content.validationErrors.map ((error) =>
1804
1812
error.message (zulipLocalizations));
1805
- showErrorDialog (context: context ,
1813
+ showErrorDialog (context: pageContext ,
1806
1814
title: zulipLocalizations.errorMessageEditNotSaved,
1807
1815
message: validationErrorMessages.join ('\n\n ' ));
1808
1816
return ;
@@ -1825,16 +1833,16 @@ class _EditMessageBanner extends _Banner {
1825
1833
}
1826
1834
1827
1835
@override
1828
- Widget buildTrailing (context ) {
1829
- final zulipLocalizations = ZulipLocalizations .of (context );
1836
+ Widget buildTrailing (pageContext ) {
1837
+ final zulipLocalizations = ZulipLocalizations .of (pageContext );
1830
1838
return Row (mainAxisSize: MainAxisSize .min, spacing: 8 , children: [
1831
1839
ZulipWebUiKitButton (label: zulipLocalizations.composeBoxBannerButtonCancel,
1832
1840
onPressed: composeBoxState.endEditInteraction),
1833
1841
// TODO(#1481) disabled appearance when there are validation errors
1834
1842
// or the original raw content hasn't loaded yet
1835
1843
ZulipWebUiKitButton (label: zulipLocalizations.composeBoxBannerButtonSave,
1836
1844
attention: ZulipWebUiKitButtonAttention .high,
1837
- onPressed: () => _handleTapSave (context )),
1845
+ onPressed: () => _handleTapSave (pageContext )),
1838
1846
]);
1839
1847
}
1840
1848
}
0 commit comments