Last active
November 16, 2025 14:20
-
-
Save lukepighetti/6436ff0eae596e3f7ee2b23990003bce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:context_watch/context_watch.dart'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:flutter_solidart/flutter_solidart.dart'; | |
| class TestPage extends StatefulWidget { | |
| const TestPage({super.key}); | |
| @override | |
| State<TestPage> createState() => _TestPageState(); | |
| } | |
| class _TestPageState extends State<TestPage> { | |
| final useFirstStream = Signal(true); | |
| Stream<String> firstStream() => Stream.periodic( | |
| Duration(seconds: 1), | |
| (i) => "First stream: $i", | |
| ); | |
| Stream<String> secondStream() => Stream.periodic( | |
| Duration(seconds: 1), | |
| (j) => "Second stream: $j", | |
| ); | |
| late final resource = Resource.stream( | |
| () => useFirstStream() ? firstStream() : secondStream(), | |
| source: useFirstStream, | |
| ); | |
| @override | |
| Widget build(BuildContext context) { | |
| final value = resource.watch(context).value; | |
| useFirstStream.watch(context); | |
| return Material( | |
| child: Center( | |
| child: Column( | |
| mainAxisSize: MainAxisSize.min, | |
| children: [ | |
| // ⚠️ doesn't react to useFirstStream dependency signal changing | |
| Text( | |
| "Test $value", | |
| ), | |
| FilledButton( | |
| onPressed: () { | |
| useFirstStream.updateValue((x) => !x); | |
| }, | |
| child: Text( | |
| useFirstStream() ? "Using first stream" : "Using second stream", | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment