Skip to content

Commit f4521f5

Browse files
committed
compose [nfc]: Let _Banner's subclasses define their own banner label
When we add a _Banner subclass for the edit-message compose box, we'd like it to control its own label instead of expecting it from callers.
1 parent 046abdb commit f4521f5

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lib/widgets/compose_box.dart

+16-9
Original file line numberDiff line numberDiff line change
@@ -1321,10 +1321,9 @@ class StreamComposeBoxController extends ComposeBoxController {
13211321
class FixedDestinationComposeBoxController extends ComposeBoxController {}
13221322

13231323
abstract class _Banner extends StatelessWidget {
1324-
const _Banner({required this.label});
1325-
1326-
final String label;
1324+
const _Banner();
13271325

1326+
String getLabel(ZulipLocalizations zulipLocalizations);
13281327
Color getLabelColor(DesignVariables designVariables);
13291328
Color getBackgroundColor(DesignVariables designVariables);
13301329

@@ -1342,6 +1341,7 @@ abstract class _Banner extends StatelessWidget {
13421341

13431342
@override
13441343
Widget build(BuildContext context) {
1344+
final zulipLocalizations = ZulipLocalizations.of(context);
13451345
final designVariables = DesignVariables.of(context);
13461346
final labelTextStyle = TextStyle(
13471347
fontSize: 17,
@@ -1365,7 +1365,7 @@ abstract class _Banner extends StatelessWidget {
13651365
child: Padding(
13661366
padding: const EdgeInsets.symmetric(vertical: 4),
13671367
child: Text(style: labelTextStyle,
1368-
label))),
1368+
getLabel(zulipLocalizations)))),
13691369
if (trailing != null) ...[
13701370
const SizedBox(width: 8),
13711371
trailing,
@@ -1375,7 +1375,14 @@ abstract class _Banner extends StatelessWidget {
13751375
}
13761376

13771377
class _ErrorBanner extends _Banner {
1378-
const _ErrorBanner({required super.label});
1378+
const _ErrorBanner({
1379+
required String Function(ZulipLocalizations) getLabel,
1380+
}) : _getLabel = getLabel;
1381+
1382+
@override
1383+
String getLabel(ZulipLocalizations zulipLocalizations) =>
1384+
_getLabel(zulipLocalizations);
1385+
final String Function(ZulipLocalizations) _getLabel;
13791386

13801387
@override
13811388
Color getLabelColor(DesignVariables designVariables) =>
@@ -1466,16 +1473,16 @@ class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateM
14661473
final channel = store.streams[streamId];
14671474
if (channel == null || !store.hasPostingPermission(inChannel: channel,
14681475
user: store.selfUser, byDate: DateTime.now())) {
1469-
return _ErrorBanner(label:
1470-
ZulipLocalizations.of(context).errorBannerCannotPostInChannelLabel);
1476+
return _ErrorBanner(getLabel: (zulipLocalizations) =>
1477+
zulipLocalizations.errorBannerCannotPostInChannelLabel);
14711478
}
14721479

14731480
case DmNarrow(:final otherRecipientIds):
14741481
final hasDeactivatedUser = otherRecipientIds.any((id) =>
14751482
!(store.getUser(id)?.isActive ?? true));
14761483
if (hasDeactivatedUser) {
1477-
return _ErrorBanner(label:
1478-
ZulipLocalizations.of(context).errorBannerDeactivatedDmLabel);
1484+
return _ErrorBanner(getLabel: (zulipLocalizations) =>
1485+
zulipLocalizations.errorBannerDeactivatedDmLabel);
14791486
}
14801487

14811488
case CombinedFeedNarrow():

0 commit comments

Comments
 (0)