Skip to content

Commit 3e32074

Browse files
committed
compose [nfc]: Extract _ComposeButton
Not all buttons are about uploading files, while most of the buttons on the compose box share the same design. Extract that part for later use. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 97cb822 commit 3e32074

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

lib/widgets/compose_box.dart

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -990,15 +990,33 @@ Future<void> _uploadFiles({
990990
}
991991
}
992992

993-
abstract class _AttachUploadsButton extends StatelessWidget {
994-
const _AttachUploadsButton({required this.controller, required this.enabled});
993+
abstract class _ComposeButton extends StatelessWidget {
994+
const _ComposeButton({required this.controller, required this.enabled});
995995

996996
final ComposeBoxController controller;
997997
final bool enabled;
998998

999999
IconData get icon;
10001000
String tooltip(ZulipLocalizations zulipLocalizations);
10011001

1002+
void handlePress(BuildContext context);
1003+
1004+
@override
1005+
Widget build(BuildContext context) {
1006+
final designVariables = DesignVariables.of(context);
1007+
final zulipLocalizations = ZulipLocalizations.of(context);
1008+
return SizedBox(
1009+
width: _composeButtonSize,
1010+
child: IconButton(
1011+
icon: Icon(icon, color: designVariables.foreground.withFadedAlpha(0.5)),
1012+
tooltip: tooltip(zulipLocalizations),
1013+
onPressed: enabled ? () => handlePress(context) : null));
1014+
}
1015+
}
1016+
1017+
abstract class _AttachUploadsButton extends _ComposeButton {
1018+
const _AttachUploadsButton({required super.controller, required super.enabled});
1019+
10021020
/// Request files from the user, in the way specific to this upload type.
10031021
///
10041022
/// Subclasses should manage the interaction completely, e.g., by catching and
@@ -1008,7 +1026,8 @@ abstract class _AttachUploadsButton extends StatelessWidget {
10081026
/// return an empty [Iterable] after showing user feedback as appropriate.
10091027
Future<Iterable<_File>> getFiles(BuildContext context);
10101028

1011-
void _handlePress(BuildContext context) async {
1029+
@override
1030+
void handlePress(BuildContext context) async {
10121031
final files = await getFiles(context);
10131032
if (files.isEmpty) {
10141033
return; // Nothing to do (getFiles handles user feedback)
@@ -1026,18 +1045,6 @@ abstract class _AttachUploadsButton extends StatelessWidget {
10261045
contentFocusNode: controller.contentFocusNode,
10271046
files: files);
10281047
}
1029-
1030-
@override
1031-
Widget build(BuildContext context) {
1032-
final designVariables = DesignVariables.of(context);
1033-
final zulipLocalizations = ZulipLocalizations.of(context);
1034-
return SizedBox(
1035-
width: _composeButtonSize,
1036-
child: IconButton(
1037-
icon: Icon(icon, color: designVariables.foreground.withFadedAlpha(0.5)),
1038-
tooltip: tooltip(zulipLocalizations),
1039-
onPressed: enabled ? () => _handlePress(context) : null));
1040-
}
10411048
}
10421049

10431050
Future<Iterable<_File>> _getFilePickerFiles(BuildContext context, FileType type) async {

0 commit comments

Comments
 (0)