我试图使一个计算器应用程序.为此,我希望光标是一个指针上的按钮和一个正常的箭头无处不在.但一旦,我使光标是一个指针上的按钮,它仍然是一个指针在按钮之间的空间.
代码如下:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.green[400],
title: Text('Calculator'),
centerTitle: true,
titleTextStyle:
TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
body: Column(
children: [
Container(
color: Colors.amber[600],
margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
width: 435,
height: 300,
),
MouseRegion(
child: Container(
color: Colors.blue[600],
width: 435,
height: 350,
child: GridView.count(
crossAxisCount: 4,
children: [
MouseRegion(
child: Container(
width: 10,
height: 10,
color: Colors.black,
margin: EdgeInsets.all(10) ,
),
cursor: SystemMouseCursors.click,
onExit: (event) => {},
),
MouseRegion(
child: Container(
width: 10,
height: 10,
color: Colors.black,
margin: EdgeInsets.all(10),
),
cursor: SystemMouseCursors.click,
),
MouseRegion(
child: Container(
width: 10,
height: 10,
color: Colors.black,
margin: EdgeInsets.all(10),
),
cursor: SystemMouseCursors.click,
),
MouseRegion(
child: Container(
width: 10,
height: 10,
color: Colors.black,
margin: EdgeInsets.all(10),
),
cursor: SystemMouseCursors.click,
),
MouseRegion(
child: Container(
width: 10,
height: 10,
color: Colors.black,
margin: EdgeInsets.all(10),
),
cursor: SystemMouseCursors.click,
),
MouseRegion(
child: Container(
width: 10,
height: 10,
color: Colors.black,
margin: EdgeInsets.all(10),
),
cursor: SystemMouseCursors.click,
),
],
),
),
cursor: SystemMouseCursors.text,
),
],
),
),
);
}
}
我得到了这个结果:
但光标也在这些绿色标记的区域中发生变化。
我希望光标是正常的箭头在这些地区不点击一样,在黑色区域。和systemMouseCursor.text也没有影响。
1条答案
按热度按时间h6my8fg21#
要将光标更改为按钮之间的普通箭头,可以使用GestureDetector小部件 Package GridView.count小部件,并将其行为属性设置为HitTestBehavior.translucent。这允许GestureDetector捕获手势并仅在手势位于GridView.count小部件内时更改光标。
下面是修改后的代码:
通过此修改,光标将是按钮之间空间中的普通箭头和按钮上的指针。