android - Flutter-如何制作多个 notifyListeners()?
问题描述
在这里,我试图将一些图像和视频传递给纸质课程,但我想一次更新一门课程。当我调用notifyListeners();
它时,它会更新所有类,但我想为不同的类制作单独的模型。例如:如果我想更新,ImgeScalling
那么notifyListeners();
只更新ImgeScalling
。
Widget build(BuildContext context) {
return ScopedModelDescendant<ActivityModel>(
builder: (context, child, model) => Stack(
children: <Widget>[
ImageTemplate(),
Drawing(model.controller),
ImageScaling(imagePath:model.getImagePath),
// TODO: Undo and Clear button added fo temp , later need to remove
Align(
alignment: Alignment.bottomRight,
heightFactor: 100.0,
child:
Row(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
IconButton(
icon: Icon(Icons.undo),
iconSize: 40.0,
color: Colors.red,
onPressed: () => model.controller.undo()),
IconButton(
icon: Icon(Icons.clear),
iconSize: 40.0,
color: Colors.red,
onPressed: () => model.controller.clear()),
]),
)
],
));
}
return ScopedModelDescendant<ActivityModel>(
builder: (context, child, model) => PopupGridView(
side: side,
onUserPress: (text) {
print(text);
switch (text) {
// TODO: later change static image base code into index base
case 'assets/stickers/drawing/pencil.png':
model.controller.thickness = 5.0;
break;
case 'assets/stickers/drawing/brush.png':
model.controller.thickness = 10.0;
break;
case 'assets/stickers/drawing/brush1.png':
model.controller.thickness = 20.0;
break;
case 'assets/stickers/mic/stop.png':
if (!recorder.isRecording) {
recorder.start();
} else {
recorder.stop();
}
break;
case 'assets/stickers/mic/play.png':
if (recorder.isRecorded) {
recorder.playAudio();
} else {
recorder.stopAudio();
}
break;
case 'assets/stickers/camera/camera1.png':
new Camera().openCamera().then((p) {
if(p!=null)
model.setImagePath(p);
});
break;
case 'assets/stickers/camera/gallery.png':
new Camera().pickImage().then((p) {
if(p!=null)
model.setImagePath(p);
});
break;
case 'assets/stickers/camera/video.png':
new Camera().vidoeRecorder().then((p){
//model.setVideoPath(p);
});
break;
}
},
bottomItems: bottomStickers,
topItems: topStickers,
itemCrossAxisCount: 2,
buildItem: buildItem,
buildIndexItem: buildIndexItem,
));
class ActivityModel extends Model {
PainterController _controller;
ActivityModel() {
_controller = new PainterController();
}
PainterController get controller => this._controller;
List<String> _imagePath=[];
File _videoPath;
List<String> get getImagePath => _imagePath;
File get getVideoPath => _videoPath;
void setImagePath(String str) {
_imagePath.add(str);
print('list of images::$_imagePath');
notifyListeners();
}
void setVideoPath(File str) {
_videoPath=str;
notifyListeners();
}
}
解决方案
推荐阅读
- python - auto_arima(... ,seasonal=False) 但得到 SARIMAX
- ios - 将 Apple 证书和配置文件导入 Azure Pipeline
- javascript - Javascript:innerHTML 导致 NaN 返回值
- javascript - Chrome 离线存储无法在 iOS 上运行
- python-3.x - 让一个模块处理数据库连接
- ios - Swift - 将嵌套的 JSON 转换为字典
- javascript - 斐波那契序列 javascript
- javascript - jQuery Maphilight 在关闭和重新打开模式后不起作用
- javascript - 使用其 API 从 Hubspot 检索交易
- android - Android 多用户行为:如何为所有用户安装应用程序包