从另一个 dart.file (Flutter) 导入和调用 Class 的代码有什么区别

What is the difference between the codes for importing and calling Class from another dart.file (Flutter)

1) 如您所见,我正在练习 flutter bloc pattern。 这里有很多进口商品。它们之间有什么区别? (包:bloc/bloc.dart)(bloc.dart)(包:test1/bloc.dart) test1 是我的项目名称。

2) 然后我尝试调用 bloc.dart 文件中的 Bloc Class。但它说 Bloc() 不是函数。我该怎么办?

还有我的 bloc.dart 文件:

包导入和相对导入之间没有实际区别,但为了代码的易读性和组织性,包导入更受欢迎。此外,当您从某个位置更改文件并且必须重命名所有导入时,相对导入往往会很痛苦。

您 "can" 对同一文件使用两种导入,因为 Dart 将它们视为 2 个不同的命名空间,但这可能会导致错误,可能这就是导致错误的原因。

关于BLoC模式,看来你用的是BLoC的纯内核,建议你研究一下flutter_bloc (which is made by the BLoC team). It's the way that BLoC is used more often. There is also a great documentation by the BLoC team in here的实现。