fix: фикс расположения текста в инлайн кнопке типа clipboard

This commit is contained in:
Jganenokk
2026-08-15 21:43:14 +07:00
parent f7a986fec7
commit 3f4c627276
2 changed files with 85 additions and 2 deletions
+4 -2
View File
@@ -1322,10 +1322,12 @@ class MessageBubble extends StatelessWidget {
child: Stack( child: Stack(
children: [ children: [
Padding( Padding(
padding: EdgeInsets.fromLTRB(isClipboard ? 26 : 12, 10, 12, 10), padding: EdgeInsets.symmetric(
horizontal: isClipboard ? 26 : 12,
vertical: 10,
),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [ children: [
Flexible( Flexible(
child: Text( child: Text(
+81
View File
@@ -0,0 +1,81 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:komet/backend/modules/messages.dart';
import 'package:komet/frontend/widgets/message_bubble.dart';
import 'package:komet/l10n/app_localizations.dart';
const int _me = 1;
CachedMessage _withButton(Map<String, dynamic> button) =>
CachedMessage.fromPushPayload(_me, 2, {
'id': '7007',
'time': DateTime(2026, 1, 1, 12, 30).millisecondsSinceEpoch,
'type': 'USER',
'sender': 2,
'text': 'Ваш код',
'attaches': [
{
'_type': 'INLINE_KEYBOARD',
'keyboard': {
'buttons': [
[button],
],
},
},
],
});
Future<void> _pump(WidgetTester tester, CachedMessage message) async {
await tester.pumpWidget(
MaterialApp(
locale: const Locale('ru'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: MessageBubble(
message: message,
isMe: false,
myId: _me,
chatType: 'DIALOG',
),
),
),
),
);
await tester.pump();
}
double _horizontalDrift(WidgetTester tester, String label) {
final button = tester.getRect(
find.ancestor(of: find.text(label), matching: find.byType(InkWell)).first,
);
final text = tester.getRect(find.text(label));
return text.center.dx - button.center.dx;
}
void main() {
testWidgets('a clipboard button keeps its label centred', (tester) async {
await _pump(tester, _withButton({
'type': 'CLIPBOARD',
'text': 'Копировать',
'payload': '123456',
}));
expect(find.text('Копировать'), findsOneWidget);
expect(_horizontalDrift(tester, 'Копировать').abs(), lessThan(0.5));
});
testWidgets('a plain callback button keeps its label centred', (
tester,
) async {
await _pump(tester, _withButton({
'type': 'CALLBACK',
'text': 'Продолжить',
'payload': 'go',
}));
expect(_horizontalDrift(tester, 'Продолжить').abs(), lessThan(0.5));
});
}