【发布时间】:2013-12-25 15:20:02
【问题描述】:
我正在探索 Dart 的观察库中的 ChangeNotifier 类,以便在命令行应用程序中使用。但是,我有两个问题。
-
List<ChangeRecord>对象中报告的更改数在每次更新记录时会递增重复。见图片: -
ChangeRecord 不允许仅检索新值。因此,我尝试改用 MapChangeRecord。但是,我不知道如何使用它。
这是我的示例代码供参考:
import 'dart:io';
import 'dart:async';
import 'dart:convert';
import 'package:observe/observe.dart';
class Notifiable extends Object with ChangeNotifier {
String _input = '';
@reflectable get input => _input;
@reflectable set input(val) {
_input = notifyPropertyChange(#input, _input, val);
}
void change(String text) {
input = text;
this.changes.listen((List<ChangeRecord> record) => print(record.last));
}
}
void main() {
Notifiable notifiable = new Notifiable();
Stream stdinStream = stdin;
stdinStream
.transform(new Utf8Decoder())
.listen((e) => notifiable.change(e));
}
【问题讨论】:
标签: dart