Skip to content

Commit aa6e570

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 f34bdf3 commit aa6e570

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
@@ -978,14 +978,32 @@ Future<void> _uploadFiles({
978978
}
979979
}
980980

981-
abstract class _AttachUploadsButton extends StatelessWidget {
982-
const _AttachUploadsButton({required this.controller});
981+
abstract class _ComposeButton extends StatelessWidget {
982+
const _ComposeButton({required this.controller});
983983

984984
final ComposeBoxController controller;
985985

986986
IconData get icon;
987987
String tooltip(ZulipLocalizations zulipLocalizations);
988988

989+
void handlePress(BuildContext context);
990+
991+
@override
992+
Widget build(BuildContext context) {
993+
final designVariables = DesignVariables.of(context);
994+
final zulipLocalizations = ZulipLocalizations.of(context);
995+
return SizedBox(
996+
width: _composeButtonSize,
997+
child: IconButton(
998+
icon: Icon(icon, color: designVariables.foreground.withFadedAlpha(0.5)),
999+
tooltip: tooltip(zulipLocalizations),
1000+
onPressed: () => handlePress(context)));
1001+
}
1002+
}
1003+
1004+
abstract class _AttachUploadsButton extends _ComposeButton {
1005+
const _AttachUploadsButton({required super.controller});
1006+
9891007
/// Request files from the user, in the way specific to this upload type.
9901008
///
9911009
/// Subclasses should manage the interaction completely, e.g., by catching and
@@ -995,7 +1013,8 @@ abstract class _AttachUploadsButton extends StatelessWidget {
9951013
/// return an empty [Iterable] after showing user feedback as appropriate.
9961014
Future<Iterable<_File>> getFiles(BuildContext context);
9971015

998-
void _handlePress(BuildContext context) async {
1016+
@override
1017+
void handlePress(BuildContext context) async {
9991018
final files = await getFiles(context);
10001019
if (files.isEmpty) {
10011020
return; // Nothing to do (getFiles handles user feedback)
@@ -1013,18 +1032,6 @@ abstract class _AttachUploadsButton extends StatelessWidget {
10131032
contentFocusNode: controller.contentFocusNode,
10141033
files: files);
10151034
}
1016-
1017-
@override
1018-
Widget build(BuildContext context) {
1019-
final designVariables = DesignVariables.of(context);
1020-
final zulipLocalizations = ZulipLocalizations.of(context);
1021-
return SizedBox(
1022-
width: _composeButtonSize,
1023-
child: IconButton(
1024-
icon: Icon(icon, color: designVariables.foreground.withFadedAlpha(0.5)),
1025-
tooltip: tooltip(zulipLocalizations),
1026-
onPressed: () => _handlePress(context)));
1027-
}
10281035
}
10291036

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

0 commit comments

Comments
 (0)