felangel/inherited_stream
用於 Stream 的繼承小部件,當流發出資料時會更新其相依性。
- Stars
- 23
- Forks
- 2
- 最近推送(UTC)
- 2025年3月27日
- 專案狀態
- 未封存
語言C++CMakeDartHTMLCSwiftKotlinObjective-C
使用的依賴
依賴清單 2 項
- flutter
{"sdk":"flutter"} - flutter_test開發依賴
{"sdk":"flutter"}
原始 README
以下為英文專案原文快照,最新內容請造訪 GitHub。
展開 / 收合專案 README
Inherited Stream
Pub build coverage License: MIT
An InheritedWidget for Streams, which updates its dependencies when the Stream emits.
Usage
Create an InheritedStream
class ProgressModel extends InheritedStream<ValueStream<double>> {
const ProgressModel({
Key? key,
required ValueStream<double> stream,
required Widget child,
}) : super(key: key, stream: stream, child: child);
static double of(BuildContext context) {
return context
.dependOnInheritedWidgetOfExactType<ProgressModel>()!
.stream
.value!;
}
}
Insert into the Widget Tree
class _MyState extends State<MyPage> {
final _subject = BehaviorSubject<double>.seeded(0.0);
@override
void dispose() {
_subject.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ProgressModel(
stream: _subject.stream,
child: Progress(),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _subject.add(Random.nextDouble()),
),
);
}
}
Register Dependant(s)
class Progress extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CircularProgressIndicator(value: ProgressModel.of(context));
}
}