正如本教程所述,我试图将自己的状态与视图分开:https://blog.usejournal.com/easily-navigate-through-your-flutter-code-by-separating-view-and-view-model-240026191106。不幸的是,看起来Flutter期望createState
返回一个直接扩展State<>
而不是另一个类的子类的对象。
例外:
StatefulWidget.createState must return a subtype of State<RateAdvisorScreen>. The createState function for RateAdvisorScreen returned a state of type RateAdvisorView, which is not a subtype of State<RateAdvisorScreen>, violating the contract for createState.
这是我的班级定义:
class RateAdvisorScreen extends StatefulWidget
abstract class RateAdvisorState extends State<RateAdvisorScreen>
class RateAdvisorView extends RateAdvisorState
任何帮助将不胜感激。谢谢。
其他信息
这似乎仅在将视图类分离到其自己的文件中时发生。如果在同一个文件中定义了所有三个类,则没有问题。