Flutter 引入类库API冲突解决

报错如下:

Try correcting the name to match an existing function, or define a method or function named 'ScreenUtil'. The name 'ScreenUtil' is defined in the libraries 'package:flustars/src/screen_util.dart (via package:flustars/flustars.dart)' and 'package:flutter_screenutil/flutter_screenutil.dart'. (Documentation) Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.
开始没看清是哪个类库,搞的比较晕。

解决方法:

其实说的也很明白了,就是这两个库都有这个API,解决方法就是要么在其中的一个的导入加上“as前缀”:

import 'package:flutter_screenutil/flutter_screenutil.dart' as scrren;

区分两个类库的API。

要么隐藏另外一个:

import 'package:flustars/flustars.dart' hide ScreenUtil;

都可以,二选一。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。