Flutter 解决Type ‘MouseCursor‘ not found.

简介: Flutter 解决Type ‘MouseCursor‘ not found.

出现场景

开发环境

adodeMacBook-Pro:~ ado$ flutter --version
Flutter 2.0.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4d7946a68d (6 months ago) • 2021-03-18 17:24:33 -0700
Engine • revision 3459eb2436
Tools • Dart 2.12.2

项目中需要展示图表,去pub上找了个库fl_chart,看起来很不错,于是准备拿来用。我用的时候最新版本是0.40.0,添加到pubspec.yaml,运行出现以后错误。

../../../dev_tools/flutter/.pub-cache/hosted/pub.flutter-io.cn/fl_chart-0.40.0/lib/src/chart/base/base_chart/base_chart_data.dart:199:60: Error: Type 'MouseCursor' not found.
typedef MouseCursorResolver<R extends BaseTouchResponse> = MouseCursor Function(FlTouchEvent, R?);
                                                           ^^^^^^^^^^^


FAILURE: Build failed with an exception.

解决方法

看错误指的是MouseCursor这个类找不到。MouseCursor是desktop平台的鼠标光标,看样子应该属于Flutter高版本API的类。所以我们只需要将Flutter版本升级或者使用低版本的库。

方法1:升级Flutter

我目前的版本是Flutter 2.0,升级到Flutter 2.2以上即可。

方法2:使用兼容低版本的三方库

在pub库中,切换到version选项,从下面版本一个一个试,


切换到0.36.4,重新运行,发现正常,问题解决。

其他库的解决方法同时,新的版本不行,就继续换成老的版本一个一个试。

相关文章
|
3月前
Flutter-解决Try catch出现异常:type ‘_TypeError‘ is not a subtype of type ‘Exception‘ in type cast
Flutter-解决Try catch出现异常:type ‘_TypeError‘ is not a subtype of type ‘Exception‘ in type cast
80 1
|
3月前
|
Dart JavaScript 前端开发
Dart或Flutter中解决异常-type ‘int‘ is not a subtype of type ‘double‘
Dart或Flutter中解决异常-type ‘int‘ is not a subtype of type ‘double‘
137 4
|
3月前
Flutter更改主题颜色报错:type ‘Color‘ is not a subtype of type ‘MaterialColor‘
Flutter更改主题颜色报错:type ‘Color‘ is not a subtype of type ‘MaterialColor‘
44 4
|
3月前
|
缓存 iOS开发
Flutter run出现No Provisioning Profile was found for your project‘s Bundle Identifier or your device
Flutter run出现No Provisioning Profile was found for your project‘s Bundle Identifier or your device
44 2
|
3月前
|
存储 JSON 数据格式
解决使用flutter_intl出现警告No @@locale or _locale field found in intl_en
解决使用flutter_intl出现警告No @@locale or _locale field found in intl_en
76 2
|
3月前
|
Dart 开发工具
解决升级Flutter3.0后出现警告Operand of null-aware operation ‘!‘ has type ‘WidgetsBinding‘ which excludes null
解决升级Flutter3.0后出现警告Operand of null-aware operation ‘!‘ has type ‘WidgetsBinding‘ which excludes null
38 1
|
3月前
|
开发工具 Android开发
Flutter: Android SDK not found at this location,Android Studio not found at xxx
Flutter: Android SDK not found at this location,Android Studio not found at xxx
159 2
Flutter的setState的使用注意事项以及报错The method ‘setState‘ isn‘t defined for the type
Flutter的setState的使用注意事项以及报错The method ‘setState‘ isn‘t defined for the type
【错误记录】Flutter 使用 MediaQuery 适配全面屏报错 ( No MediaQuery widget ancestor found. )
【错误记录】Flutter 使用 MediaQuery 适配全面屏报错 ( No MediaQuery widget ancestor found. )
865 0
【错误记录】Flutter 使用 MediaQuery 适配全面屏报错 ( No MediaQuery widget ancestor found. )
|
Dart 开发工具 Kotlin
【错误记录】Flutter 编译报错 ( The parameter ‘‘ can‘t have a value of ‘null‘ because of its type, but the im )
【错误记录】Flutter 编译报错 ( The parameter ‘‘ can‘t have a value of ‘null‘ because of its type, but the im )
660 0
【错误记录】Flutter 编译报错 ( The parameter ‘‘ can‘t have a value of ‘null‘ because of its type, but the im )