1
+ import 'dart:async' ;
1
2
import 'dart:math' ;
2
3
3
4
import 'package:collection/collection.dart' ;
5
+ import 'package:flutter/gestures.dart' ;
4
6
import 'package:flutter/material.dart' ;
5
7
import 'package:flutter_color_models/flutter_color_models.dart' ;
6
8
import 'package:intl/intl.dart' hide TextDirection;
@@ -16,6 +18,7 @@ import 'actions.dart';
16
18
import 'app_bar.dart' ;
17
19
import 'compose_box.dart' ;
18
20
import 'content.dart' ;
21
+ import 'dialog.dart' ;
19
22
import 'emoji_reaction.dart' ;
20
23
import 'icons.dart' ;
21
24
import 'page.dart' ;
@@ -1318,22 +1321,45 @@ String formatHeaderDate(
1318
1321
// Design referenced from:
1319
1322
// - https://github.com/zulip/zulip-mobile/issues/5511
1320
1323
// - https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=538%3A20849&mode=dev
1321
- class MessageWithPossibleSender extends StatelessWidget {
1324
+ class MessageWithPossibleSender extends StatefulWidget {
1322
1325
const MessageWithPossibleSender ({super .key, required this .item});
1323
1326
1324
1327
final MessageListMessageItem item;
1325
1328
1329
+ @override
1330
+ State <MessageWithPossibleSender > createState () => _MessageWithPossibleSenderState ();
1331
+ }
1332
+
1333
+ class _MessageWithPossibleSenderState extends State <MessageWithPossibleSender > {
1334
+ final WidgetStatesController statesController = WidgetStatesController ();
1335
+
1336
+ @override
1337
+ void initState () {
1338
+ super .initState ();
1339
+ statesController.addListener (() {
1340
+ setState (() {
1341
+ // Force a rebuild to resolve background color
1342
+ });
1343
+ });
1344
+ }
1345
+
1346
+ @override
1347
+ void dispose () {
1348
+ statesController.dispose ();
1349
+ super .dispose ();
1350
+ }
1351
+
1326
1352
@override
1327
1353
Widget build (BuildContext context) {
1328
1354
final store = PerAccountStoreWidget .of (context);
1329
1355
final messageListTheme = MessageListTheme .of (context);
1330
1356
final designVariables = DesignVariables .of (context);
1331
1357
1332
- final message = item.message;
1358
+ final message = widget. item.message;
1333
1359
final sender = store.getUser (message.senderId);
1334
1360
1335
1361
Widget ? senderRow;
1336
- if (item.showSender) {
1362
+ if (widget. item.showSender) {
1337
1363
final time = _kMessageTimestampFormat
1338
1364
.format (DateTime .fromMillisecondsSinceEpoch (1000 * message.timestamp));
1339
1365
senderRow = Row (
@@ -1400,40 +1426,62 @@ class MessageWithPossibleSender extends StatelessWidget {
1400
1426
child: Icon (ZulipIcons .star_filled, size: 16 , color: designVariables.star));
1401
1427
}
1402
1428
1403
- return GestureDetector (
1429
+ return RawGestureDetector (
1404
1430
behavior: HitTestBehavior .translucent,
1405
- onLongPress: () => showMessageActionSheet (context: context, message: message),
1406
- child: Padding (
1407
- padding: const EdgeInsets .symmetric (vertical: 4 ),
1408
- child: Column (children: [
1409
- if (senderRow != null )
1410
- Padding (padding: const EdgeInsets .fromLTRB (16 , 2 , 16 , 0 ),
1411
- child: senderRow),
1412
- Row (
1413
- crossAxisAlignment: CrossAxisAlignment .baseline,
1414
- textBaseline: localizedTextBaseline (context),
1415
- children: [
1416
- const SizedBox (width: 16 ),
1417
- Expanded (child: Column (
1418
- crossAxisAlignment: CrossAxisAlignment .stretch,
1419
- children: [
1420
- MessageContent (message: message, content: item.content),
1421
- if ((message.reactions? .total ?? 0 ) > 0 )
1422
- ReactionChipsList (messageId: message.id, reactions: message.reactions! ),
1423
- if (editStateText != null )
1424
- Text (editStateText,
1425
- textAlign: TextAlign .end,
1426
- style: TextStyle (
1427
- color: designVariables.labelEdited,
1428
- fontSize: 12 ,
1429
- height: (12 / 12 ),
1430
- letterSpacing: proportionalLetterSpacing (
1431
- context, 0.05 , baseFontSize: 12 ))),
1432
- ])),
1433
- SizedBox (width: 16 ,
1434
- child: star),
1435
- ]),
1436
- ])));
1431
+ gestures: < Type , GestureRecognizerFactory > {
1432
+ LongPressGestureRecognizer : GestureRecognizerFactoryWithHandlers <LongPressGestureRecognizer >(
1433
+ () => LongPressGestureRecognizer (duration: Duration (milliseconds: 600 )),
1434
+ (instance) {
1435
+ instance.onLongPress = () async {
1436
+ statesController.update (WidgetState .selected, true );
1437
+ ModalStatus status = showMessageActionSheet (context: context,
1438
+ message: message);
1439
+ await status.closed;
1440
+ statesController.update (WidgetState .selected, false );
1441
+ };
1442
+ instance.onLongPressDown = (_) => statesController.update (WidgetState .pressed, true );
1443
+ instance.onLongPressCancel = () => statesController.update (WidgetState .pressed, false );
1444
+ instance.onLongPressUp = () => statesController.update (WidgetState .pressed, false );
1445
+ },
1446
+ ),
1447
+ },
1448
+ child: DecoratedBox (decoration: BoxDecoration (
1449
+ color: WidgetStateColor .fromMap ({
1450
+ WidgetState .pressed: designVariables.pressedTint,
1451
+ WidgetState .selected: designVariables.pressedTint,
1452
+ WidgetState .any: Colors .transparent,
1453
+ }).resolve (statesController.value)),
1454
+ child: Padding (
1455
+ padding: const EdgeInsets .symmetric (vertical: 4 ),
1456
+ child: Column (children: [
1457
+ if (senderRow != null )
1458
+ Padding (padding: const EdgeInsets .fromLTRB (16 , 2 , 16 , 0 ),
1459
+ child: senderRow),
1460
+ Row (
1461
+ crossAxisAlignment: CrossAxisAlignment .baseline,
1462
+ textBaseline: localizedTextBaseline (context),
1463
+ children: [
1464
+ const SizedBox (width: 16 ),
1465
+ Expanded (child: Column (
1466
+ crossAxisAlignment: CrossAxisAlignment .stretch,
1467
+ children: [
1468
+ MessageContent (message: message, content: widget.item.content),
1469
+ if ((message.reactions? .total ?? 0 ) > 0 )
1470
+ ReactionChipsList (messageId: message.id, reactions: message.reactions! ),
1471
+ if (editStateText != null )
1472
+ Text (editStateText,
1473
+ textAlign: TextAlign .end,
1474
+ style: TextStyle (
1475
+ color: designVariables.labelEdited,
1476
+ fontSize: 12 ,
1477
+ height: (12 / 12 ),
1478
+ letterSpacing: proportionalLetterSpacing (
1479
+ context, 0.05 , baseFontSize: 12 ))),
1480
+ ])),
1481
+ SizedBox (width: 16 ,
1482
+ child: star),
1483
+ ]),
1484
+ ]))));
1437
1485
}
1438
1486
}
1439
1487
0 commit comments