Dart 颤振作用域模型

Dart 颤振作用域模型,dart,flutter,Dart,Flutter,我正试图在我的项目中创建一个范围模型,但出现了一些问题 模型类: class CartonModel extends Model{ bool playerState = false; bool get getPlayerState => playerState ; void stateOff(){ playerState = false ; notifyListeners(); } void stateOn(){ playerState = true

我正试图在我的项目中创建一个范围模型,但出现了一些问题

模型类:

 class CartonModel extends Model{
  bool playerState = false;
  bool get getPlayerState => playerState ;
  void stateOff(){
  playerState = false ;
  notifyListeners();
  }
  void stateOn(){
    playerState = true ;
     notifyListeners();
  }
}
使用范围模型包装的材质应用程序:

ScopedModel<CartonModel>(
  model: new CartonModel(),
  child: new MaterialApp( // some code )
我正在图标按钮上使用ScopedModeleScendant:

ScopedModelDescendant<CartonModel>(
      builder: (context, child, CartonModel model) =>
          new IconButton(
            icon: new Image.asset(imageUrl),
            iconSize: dimenRatio * 0.25,
            onPressed: () {
              Future<void> bottomSheetAwaitClose =
                  showModalBottomSheet<void>(
                context: context,
                builder: (BuildContext context) {
                  return MusicR();
                },
              );

              bottomSheetAwaitClose.then((void value) {
                model.stateOff();
              });
            },
          ),
    ),
我已将所有必需的包和提供的类型导入ScopedModel和ScopedModeleScendant,但仍出现以下运行时错误: 找不到正确的ScopedModel

这个代码有什么错误吗?请帮助

如果在main.dart中声明了CartonModel类,请将其移动到其他文件


并确保以“package:/cartonmodel.dart”的形式声明导入内容。

上面的代码看起来没问题。我们需要更多的代码一个完整的可运行示例来说明问题所在。感谢您的回复@boformer,它现在可以工作了它位于一个独立的文件中,并且我已经导入了所有必需的包。好的,答案试图根据我们已经见过多次的问题为您提供一些线索。在这些情况下,上述建议有助于解决这一问题。即使分析器没有抱怨,导入格式也可能会出现问题。请看一下这个线程中的解决方案。当我将所有导入语句更改为“package:/filename.dart”时,它可以工作,非常感谢您的帮助。