如图:一个黄色Container里有一个红色Text和一个绿色Text。点击红色Text打印A,点击绿色Text打印B。
现在的问题是点击第二行空白区域也会打印B,这显示不合适。
代码如下:
class DraftPage extends StatelessWidget {
DraftPage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: Container(
color: Colors.yellow,
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: 'AAAAAAAAAAAAAA',
style: TextStyle(fontSize: 20, color: Colors.red),
recognizer: TapGestureRecognizer()
..onTap = () {
print('A');
},
),
TextSpan(
text: 'BBBBBBBBBBBBBBBBBBB',
style: TextStyle(fontSize: 20, color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () {
print('B');
},
),
],
),
),
),
);
}
}
如何解决?