reduce duplicate code

This commit is contained in:
ggurdin 2025-11-04 15:23:54 -05:00
parent 5c95a4c62b
commit 77ec540693
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
4 changed files with 18 additions and 36 deletions

View file

@ -377,7 +377,7 @@ class ChatController extends State<ChatPageWithRoom>
if (evt is KeyDownEvent) {
// #Pangea
// send();
onInputBarSubmitted('');
onInputBarSubmitted();
// Pangea#
}
return KeyEventResult.handled;
@ -1756,7 +1756,7 @@ class ChatController extends State<ChatPageWithRoom>
// #Pangea
// void onInputBarSubmitted(String _) {
Future<void> onInputBarSubmitted(String _) async {
Future<void> onInputBarSubmitted() async {
// send();
try {
await choreographer.send();

View file

@ -278,7 +278,10 @@ class ChatInputRow extends StatelessWidget {
AppConfig.sendOnEnter == true && PlatformInfos.isMobile
? TextInputAction.send
: null,
onSubmitted: controller.onInputBarSubmitted,
// #Pangea
// onSubmitted: controller.onInputBarSubmitted,
onSubmitted: (_) => controller.onInputBarSubmitted(),
// Pangea#
onSubmitImage: controller.sendImageFromClipBoard,
focusNode: controller.inputFocus,
controller: controller.sendController,

View file

@ -195,7 +195,7 @@ class PangeaChatInputRow extends StatelessWidget {
PlatformInfos.isMobile
? TextInputAction.send
: null,
onSubmitted: controller.onInputBarSubmitted,
onSubmitted: (_) => controller.onInputBarSubmitted(),
onSubmitImage: controller.sendImageFromClipBoard,
focusNode: controller.inputFocus,
controller: controller.sendController,
@ -240,7 +240,7 @@ class PangeaChatInputRow extends StatelessWidget {
child: const Icon(Icons.mic_none_outlined),
)
: ChoreographerSendButton(
choreographer: controller.choreographer,
controller: controller,
),
),
],

View file

@ -1,50 +1,28 @@
import 'package:flutter/material.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreographer_state_extension.dart';
import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreographer_ui_extension.dart';
import 'package:fluffychat/pangea/choreographer/enums/assistance_state_enum.dart';
import 'package:fluffychat/pangea/choreographer/widgets/igc/paywall_card.dart';
import 'package:fluffychat/pangea/common/utils/overlay.dart';
class ChoreographerSendButton extends StatelessWidget {
final Choreographer choreographer;
final ChatController controller;
const ChoreographerSendButton({
super.key,
required this.choreographer,
required this.controller,
});
Future<void> _onPressed(BuildContext context) async {
choreographer.onClickSend();
try {
await choreographer.send();
} on ShowPaywallException {
PaywallCard.show(
context,
choreographer.inputTransformTargetKey,
);
} on OpenMatchesException {
if (choreographer.firstOpenMatch != null) {
if (choreographer.firstOpenMatch!.updatedMatch.isITStart) {
choreographer.openIT(choreographer.firstOpenMatch!);
} else {
OverlayUtil.showIGCMatch(
choreographer.firstOpenMatch!,
choreographer,
context,
);
}
}
}
controller.choreographer.onClickSend();
controller.onInputBarSubmitted();
}
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: Listenable.merge([
choreographer.textController,
choreographer.isFetching,
controller.sendController,
controller.choreographer.isFetching,
]),
builder: (context, _) {
return Container(
@ -52,8 +30,9 @@ class ChoreographerSendButton extends StatelessWidget {
alignment: Alignment.center,
child: IconButton(
icon: const Icon(Icons.send_outlined),
color: choreographer.assistanceState.sendButtonColor(context),
onPressed: choreographer.isFetching.value
color: controller.choreographer.assistanceState
.sendButtonColor(context),
onPressed: controller.choreographer.isFetching.value
? null
: () => _onPressed(context),
tooltip: L10n.of(context).send,