@@ -493,11 +493,13 @@ class _ContentInput extends StatelessWidget {
493
493
required this .narrow,
494
494
required this .controller,
495
495
required this .hintText,
496
+ this .enabled = true , // ignore: unused_element_parameter
496
497
});
497
498
498
499
final Narrow narrow;
499
500
final ComposeBoxController controller;
500
501
final String hintText;
502
+ final bool enabled;
501
503
502
504
static double maxHeight (BuildContext context) {
503
505
final clampingTextScaler = MediaQuery .textScalerOf (context)
@@ -540,6 +542,7 @@ class _ContentInput extends StatelessWidget {
540
542
top: _verticalPadding, bottom: _verticalPadding,
541
543
color: designVariables.composeBoxBg,
542
544
child: TextField (
545
+ enabled: enabled,
543
546
controller: controller.content,
544
547
focusNode: controller.contentFocusNode,
545
548
// Let the content show through the `contentPadding` so that
@@ -957,9 +960,10 @@ Future<void> _uploadFiles({
957
960
}
958
961
959
962
abstract class _AttachUploadsButton extends StatelessWidget {
960
- const _AttachUploadsButton ({required this .controller});
963
+ const _AttachUploadsButton ({required this .controller, required this .enabled });
961
964
962
965
final ComposeBoxController controller;
966
+ final bool enabled;
963
967
964
968
IconData get icon;
965
969
String tooltip (ZulipLocalizations zulipLocalizations);
@@ -1001,7 +1005,7 @@ abstract class _AttachUploadsButton extends StatelessWidget {
1001
1005
child: IconButton (
1002
1006
icon: Icon (icon, color: designVariables.foreground.withFadedAlpha (0.5 )),
1003
1007
tooltip: tooltip (zulipLocalizations),
1004
- onPressed: () => _handlePress (context)));
1008
+ onPressed: enabled ? () => _handlePress (context) : null ));
1005
1009
}
1006
1010
}
1007
1011
@@ -1060,7 +1064,7 @@ Future<Iterable<_File>> _getFilePickerFiles(BuildContext context, FileType type)
1060
1064
}
1061
1065
1062
1066
class _AttachFileButton extends _AttachUploadsButton {
1063
- const _AttachFileButton ({required super .controller});
1067
+ const _AttachFileButton ({required super .controller, required super .enabled });
1064
1068
1065
1069
@override
1066
1070
IconData get icon => ZulipIcons .attach_file;
@@ -1076,7 +1080,7 @@ class _AttachFileButton extends _AttachUploadsButton {
1076
1080
}
1077
1081
1078
1082
class _AttachMediaButton extends _AttachUploadsButton {
1079
- const _AttachMediaButton ({required super .controller});
1083
+ const _AttachMediaButton ({required super .controller, required super .enabled });
1080
1084
1081
1085
@override
1082
1086
IconData get icon => ZulipIcons .image;
@@ -1093,7 +1097,7 @@ class _AttachMediaButton extends _AttachUploadsButton {
1093
1097
}
1094
1098
1095
1099
class _AttachFromCameraButton extends _AttachUploadsButton {
1096
- const _AttachFromCameraButton ({required super .controller});
1100
+ const _AttachFromCameraButton ({required super .controller, required super .enabled });
1097
1101
1098
1102
@override
1099
1103
IconData get icon => ZulipIcons .camera;
@@ -1370,6 +1374,7 @@ abstract class _ComposeBoxBody extends StatelessWidget {
1370
1374
1371
1375
Widget ? buildTopicInput ();
1372
1376
Widget buildContentInput ();
1377
+ bool getComposeButtonsEnabled (BuildContext context);
1373
1378
Widget buildSendButton ();
1374
1379
1375
1380
@override
@@ -1396,10 +1401,11 @@ abstract class _ComposeBoxBody extends StatelessWidget {
1396
1401
shape: const RoundedRectangleBorder (
1397
1402
borderRadius: BorderRadius .all (Radius .circular (4 )))));
1398
1403
1404
+ final composeButtonsEnabled = getComposeButtonsEnabled (context);
1399
1405
final composeButtons = [
1400
- _AttachFileButton (controller: controller),
1401
- _AttachMediaButton (controller: controller),
1402
- _AttachFromCameraButton (controller: controller),
1406
+ _AttachFileButton (controller: controller, enabled : composeButtonsEnabled ),
1407
+ _AttachMediaButton (controller: controller, enabled : composeButtonsEnabled ),
1408
+ _AttachFromCameraButton (controller: controller, enabled : composeButtonsEnabled ),
1403
1409
];
1404
1410
1405
1411
final topicInput = buildTopicInput ();
@@ -1449,6 +1455,8 @@ class _StreamComposeBoxBody extends _ComposeBoxBody {
1449
1455
controller: controller,
1450
1456
);
1451
1457
1458
+ @override bool getComposeButtonsEnabled (BuildContext context) => true ;
1459
+
1452
1460
@override Widget buildSendButton () => _SendButton (
1453
1461
controller: controller,
1454
1462
getDestination: () => StreamDestination (
@@ -1472,6 +1480,8 @@ class _FixedDestinationComposeBoxBody extends _ComposeBoxBody {
1472
1480
controller: controller,
1473
1481
);
1474
1482
1483
+ @override bool getComposeButtonsEnabled (BuildContext context) => true ;
1484
+
1475
1485
@override Widget buildSendButton () => _SendButton (
1476
1486
controller: controller,
1477
1487
getDestination: () => narrow.destination,
@@ -1756,7 +1766,8 @@ class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateM
1756
1766
1757
1767
final errorBanner = _errorBannerComposingNotAllowed (context);
1758
1768
if (errorBanner != null ) {
1759
- return _ComposeBoxContainer (body: null , banner: errorBanner);
1769
+ return ComposeBoxInheritedWidget .fromComposeBoxState (this ,
1770
+ child: _ComposeBoxContainer (body: null , banner: errorBanner));
1760
1771
}
1761
1772
1762
1773
final controller = this .controller;
@@ -1777,6 +1788,39 @@ class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateM
1777
1788
// errorBanner = _ErrorBanner(label:
1778
1789
// ZulipLocalizations.of(context).errorSendMessageTimeout);
1779
1790
// }
1780
- return _ComposeBoxContainer (body: body, banner: null );
1791
+ return ComposeBoxInheritedWidget .fromComposeBoxState (this ,
1792
+ child: _ComposeBoxContainer (body: body, banner: null ));
1793
+ }
1794
+ }
1795
+
1796
+ /// An [InheritedWidget] to provide data to leafward [StatelessWidget] s,
1797
+ /// such as flags that should cause the upload buttons to be disabled.
1798
+ class ComposeBoxInheritedWidget extends InheritedWidget {
1799
+ factory ComposeBoxInheritedWidget .fromComposeBoxState (
1800
+ ComposeBoxState state, {
1801
+ required Widget child,
1802
+ }) {
1803
+ return ComposeBoxInheritedWidget ._(
1804
+ // TODO add fields
1805
+ child: child,
1806
+ );
1807
+ }
1808
+
1809
+ const ComposeBoxInheritedWidget ._({
1810
+ // TODO add fields
1811
+ required super .child,
1812
+ });
1813
+
1814
+ // TODO add fields
1815
+
1816
+ @override
1817
+ bool updateShouldNotify (covariant ComposeBoxInheritedWidget oldWidget) =>
1818
+ // TODO compare fields
1819
+ false ;
1820
+
1821
+ static ComposeBoxInheritedWidget of (BuildContext context) {
1822
+ final widget = context.dependOnInheritedWidgetOfExactType <ComposeBoxInheritedWidget >();
1823
+ assert (widget != null , 'No ComposeBoxInheritedWidget ancestor' );
1824
+ return widget! ;
1781
1825
}
1782
1826
}
0 commit comments