Skip to content

Commit d249042

Browse files
chrisbobbegnprice
authored andcommitted
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 5921cb7 commit d249042

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
@@ -1377,10 +1377,9 @@ class StreamComposeBoxController extends ComposeBoxController {
13771377
class FixedDestinationComposeBoxController extends ComposeBoxController {}
13781378

13791379
abstract class _Banner extends StatelessWidget {
1380-
const _Banner({required this.label});
1381-
1382-
final String label;
1380+
const _Banner();
13831381

1382+
String getLabel(ZulipLocalizations zulipLocalizations);
13841383
Color getLabelColor(DesignVariables designVariables);
13851384
Color getBackgroundColor(DesignVariables designVariables);
13861385

@@ -1398,6 +1397,7 @@ abstract class _Banner extends StatelessWidget {
13981397

13991398
@override
14001399
Widget build(BuildContext context) {
1400+
final zulipLocalizations = ZulipLocalizations.of(context);
14011401
final designVariables = DesignVariables.of(context);
14021402
final labelTextStyle = TextStyle(
14031403
fontSize: 17,
@@ -1421,7 +1421,7 @@ abstract class _Banner extends StatelessWidget {
14211421
child: Padding(
14221422
padding: const EdgeInsets.symmetric(vertical: 4),
14231423
child: Text(style: labelTextStyle,
1424-
label))),
1424+
getLabel(zulipLocalizations)))),
14251425
if (trailing != null) ...[
14261426
const SizedBox(width: 8),
14271427
trailing,
@@ -1431,7 +1431,14 @@ abstract class _Banner extends StatelessWidget {
14311431
}
14321432

14331433
class _ErrorBanner extends _Banner {
1434-
const _ErrorBanner({required super.label});
1434+
const _ErrorBanner({
1435+
required String Function(ZulipLocalizations) getLabel,
1436+
}) : _getLabel = getLabel;
1437+
1438+
@override
1439+
String getLabel(ZulipLocalizations zulipLocalizations) =>
1440+
_getLabel(zulipLocalizations);
1441+
final String Function(ZulipLocalizations) _getLabel;
14351442

14361443
@override
14371444
Color getLabelColor(DesignVariables designVariables) =>
@@ -1522,16 +1529,16 @@ class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateM
15221529
final channel = store.streams[streamId];
15231530
if (channel == null || !store.hasPostingPermission(inChannel: channel,
15241531
user: store.selfUser, byDate: DateTime.now())) {
1525-
return _ErrorBanner(label:
1526-
ZulipLocalizations.of(context).errorBannerCannotPostInChannelLabel);
1532+
return _ErrorBanner(getLabel: (zulipLocalizations) =>
1533+
zulipLocalizations.errorBannerCannotPostInChannelLabel);
15271534
}
15281535

15291536
case DmNarrow(:final otherRecipientIds):
15301537
final hasDeactivatedUser = otherRecipientIds.any((id) =>
15311538
!(store.getUser(id)?.isActive ?? true));
15321539
if (hasDeactivatedUser) {
1533-
return _ErrorBanner(label:
1534-
ZulipLocalizations.of(context).errorBannerDeactivatedDmLabel);
1540+
return _ErrorBanner(getLabel: (zulipLocalizations) =>
1541+
zulipLocalizations.errorBannerDeactivatedDmLabel);
15351542
}
15361543

15371544
case CombinedFeedNarrow():

0 commit comments

Comments
 (0)