prevent delay by using onDoubleTapDown instead of onDoubleTap

This commit is contained in:
csf 2022-08-24 14:57:41 +08:00
parent f4745ded23
commit 5f68c099dd

@ -62,7 +62,7 @@ class _PeerCardState extends State<_PeerCard>
: null); : null);
}, },
child: GestureDetector( child: GestureDetector(
onDoubleTap: () => _connect(peer.id), onDoubleTapDown: (_) => _connect(peer.id),
child: Obx(() => peerCardUiType.value == PeerUiType.grid child: Obx(() => peerCardUiType.value == PeerUiType.grid
? _buildPeerCard(context, peer, deco) ? _buildPeerCard(context, peer, deco)
: _buildPeerTile(context, peer, deco))), : _buildPeerTile(context, peer, deco))),
@ -168,109 +168,106 @@ class _PeerCardState extends State<_PeerCard>
BuildContext context, Peer peer, Rx<BoxDecoration?> deco) { BuildContext context, Peer peer, Rx<BoxDecoration?> deco) {
return Card( return Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
child: GestureDetector( child: Obx(
onDoubleTap: () => _connect(peer.id), () => Container(
child: Obx( decoration: deco.value,
() => Container( child: Column(
decoration: deco.value, mainAxisSize: MainAxisSize.min,
child: Column( mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min, children: [
mainAxisAlignment: MainAxisAlignment.center, Expanded(
children: [ child: Container(
Expanded( decoration: BoxDecoration(
child: Container( color: str2color('${peer.id}${peer.platform}', 0x7f),
decoration: BoxDecoration( borderRadius: BorderRadius.only(
color: str2color('${peer.id}${peer.platform}', 0x7f), topLeft: Radius.circular(20),
borderRadius: BorderRadius.only( topRight: Radius.circular(20),
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(6),
child: _getPlatformImage('${peer.platform}'),
),
Row(
children: [
Expanded(
child: FutureBuilder<String>(
future: bind.mainGetPeerOption(
id: peer.id, key: 'alias'),
builder: (_, snapshot) {
if (snapshot.hasData) {
final name = snapshot.data!.isEmpty
? '${peer.username}@${peer.hostname}'
: snapshot.data!;
return Tooltip(
message: name,
child: Text(
name,
style: TextStyle(
color: Colors.white70,
fontSize: 12),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
);
} else {
// alias has not arrived
return Center(
child: Text(
'${peer.username}@${peer.hostname}',
style: TextStyle(
color: Colors.white70,
fontSize: 12),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
));
}
},
),
),
],
),
],
).paddingAll(4.0),
),
],
),
), ),
), ),
Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Row(children: [ Expanded(
Padding( child: Column(
padding: EdgeInsets.fromLTRB(0, 4, 8, 4), crossAxisAlignment: CrossAxisAlignment.center,
child: CircleAvatar( children: [
radius: 5, Container(
backgroundColor: peer.online padding: const EdgeInsets.all(6),
? Colors.green child: _getPlatformImage('${peer.platform}'),
: Colors.yellow)), ),
Text('${peer.id}') Row(
]), children: [
InkWell( Expanded(
child: Icon(Icons.more_vert), child: FutureBuilder<String>(
onTapDown: (e) { future: bind.mainGetPeerOption(
final x = e.globalPosition.dx; id: peer.id, key: 'alias'),
final y = e.globalPosition.dy; builder: (_, snapshot) {
_menuPos = RelativeRect.fromLTRB(x, y, x, y); if (snapshot.hasData) {
}, final name = snapshot.data!.isEmpty
onTap: () { ? '${peer.username}@${peer.hostname}'
_showPeerMenu(context, peer.id); : snapshot.data!;
}), return Tooltip(
message: name,
child: Text(
name,
style: TextStyle(
color: Colors.white70,
fontSize: 12),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
);
} else {
// alias has not arrived
return Center(
child: Text(
'${peer.username}@${peer.hostname}',
style: TextStyle(
color: Colors.white70,
fontSize: 12),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
));
}
},
),
),
],
),
],
).paddingAll(4.0),
),
], ],
).paddingSymmetric(vertical: 8.0, horizontal: 12.0) ),
], ),
), ),
), Row(
)), mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 4, 8, 4),
child: CircleAvatar(
radius: 5,
backgroundColor:
peer.online ? Colors.green : Colors.yellow)),
Text('${peer.id}')
]),
InkWell(
child: Icon(Icons.more_vert),
onTapDown: (e) {
final x = e.globalPosition.dx;
final y = e.globalPosition.dy;
_menuPos = RelativeRect.fromLTRB(x, y, x, y);
},
onTap: () {
_showPeerMenu(context, peer.id);
}),
],
).paddingSymmetric(vertical: 8.0, horizontal: 12.0)
],
),
),
),
); );
} }