Flutter - vector_math 在两个地方定义

Flutter - vector_math defined in Two Places

在 flutter 项目中更新了对最新 (2.1.0) 的 vector_math 依赖,并且项目现在无法构建并出现错误:

The argument type 'Vector2 (where Vector2 is defined in /mnt/data/work/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/lib/src/vector_math_64/vector2.dart)' can't be assigned to the parameter type 'Vector2 (where Vector2 is defined in /mnt/data/work/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/lib/src/vector_math/vector2.dart)'. (Documentation)

Vector2 is defined in /mnt/data/work/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/lib/src/vector_math_64/vector2.dart (vector2.dart:10).
Vector2 is defined in /mnt/data/work/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/lib/src/vector_math/vector2.dart (vector2.dart:10).

如何解决这个问题?这是颤振问题还是 vector_math 包中的问题?

检查导入的包,错误是从不同的库导入的类型。

vector_mathvector_math_64 应该用于 32bit64bit 变体,它们在包中作为两个不同的库实现。因此,您需要保持库使用方式的一致性。

将来不再遇到此问题的可能解决方案是从基础包中导出类型,然后根据需要从 base_package 中导入这些类型,这将保护 base_package 的用户从需要知道需要什么类型或再次遇到这个问题。

例如: lib/base_package.飞镖

export 'package:vector_math/vector_math_64.dart'
or 
export 'package:vector_math/vector_math.dart'

改为

import 'package:vector_math/vector_math_64.dart';

帮我修好了。

另一个解决方案是确定范围...

import 'package:vector_math/vector_math.dart' as whatever;

请注意,确保在导入的所有地方都这样做!