Comments (8)
Can you please the code of of your Widget please?
from get_it_mixin.
Will add test project.
from get_it_mixin.
I've created a sample project at https://github.com/searchy2/get_it_mixin/tree/ray-streambuilderissue
The file with the StreamBuilder issue is at main_streambuilder.dart.
There are multiple issues with StreamBuilders that are quite confusing. I've isolated the issues as best as possible.
Issue 1: WatchX Outside Stream builder fails on hot reload rebuild
https://www.youtube.com/watch?v=7asv6UfZRbY
StreamBuilder Hot Restart Issue
class StreamBuilderHotReloadIssue extends StatefulWidget {
@override
_StreamBuilderHotReloadIssueState createState() =>
_StreamBuilderHotReloadIssueState();
}
class _StreamBuilderHotReloadIssueState
extends State<StreamBuilderHotReloadIssue> {
static StreamController<int> counterController = StreamController<int>();
Stream<int> counter = counterController.stream;
@override
void initState() {
super.initState();
Future.delayed(Duration(milliseconds: 1000), () {
counterController.add(1);
});
}
@override
void dispose() {
counterController.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
GetItCounterOutsideStreamBuilder(),
StreamBuilder(
stream: counter,
builder: (context, snapshot) {
print('Build Stream');
if (!snapshot.hasData) return SizedBox.shrink();
int counterValue = snapshot.data as int;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Stream Counter: ' + counterValue.toString()),
GetItCounterInStreamBuilder(),
],
);
},
),
],
);
}
}
Issue 2: Stream Rebuild Breaks WatchX Rebuilds.
StreamBuilder Rebuild Issue
class StreamBuilderRebuildIssue extends StatefulWidget
with GetItStatefulWidgetMixin {
@override
_StreamBuilderRebuildIssueState createState() =>
_StreamBuilderRebuildIssueState();
}
class _StreamBuilderRebuildIssueState extends State<StreamBuilderRebuildIssue>
with GetItStateMixin {
static StreamController<int> counterController = StreamController<int>();
Stream<int> counter = counterController.stream;
@override
void initState() {
super.initState();
Future.delayed(Duration(milliseconds: 1000), () {
counterController.add(1);
});
// This triggers a StreamBuilder rebuild and breaks WatchX.
Future.delayed(Duration(milliseconds: 2000), () {
counterController.add(2);
});
}
@override
void dispose() {
counterController.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
StreamBuilder(
stream: counter,
builder: (context, snapshot) {
print('Build Stream');
if (!snapshot.hasData) return SizedBox.shrink();
int counterValue = snapshot.data as int;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Stream Counter: ' + counterValue.toString()),
GetItCounterInStreamBuilder(),
GetItCounterOutsideStreamBuilder(),
],
);
},
),
],
);
}
}
from get_it_mixin.
Actually the latter makes completely sense to be because the builder has it's own context. So probably won't work together with the mixin or wit hooks. So better don't mix them inside one widget tree.
from get_it_mixin.
Just confirmed with Remi. My hunch was right. it can't work inside most builders. And the idea of the mixin is not to have to use builders to make you code more readable.
from get_it_mixin.
Concerning the hot reload I have to look.
from get_it_mixin.
I fixed the Hot reload. Please give it a try. And I added to the readme that you can't use it with Builders
from get_it_mixin.
Amazing, will test and confirm!
from get_it_mixin.
Related Issues (20)
- get watch watchOnly getX watchX watchOnlyX HOT 5
- registerHandler before a watchX causes a crash HOT 5
- getItMixin web support HOT 9
- `Watch` does not trigger rebuild HOT 13
- registerStreamHandler causes unnecessary re-renders HOT 1
- Operand of null-aware operation '!' has type ... which excludes null HOT 4
- Error using pushScope HOT 5
- error in readme HOT 1
- Strange error with get_it_mixin HOT 5
- Not able to recognize the return types. " The return type 'void' isn't a 'ValueListenable<R>', as required by the closure's context." HOT 2
- Using the watch calls on specific GetIt instance? HOT 7
- Put full license text in LICENSE file
- Question Regarding Example in Readme HOT 1
- How to use registerHandler for same subsequent calls ? HOT 2
- Watch list value changes don't trigger rebuild HOT 1
- Does this support restoration stuff like hydrated_bloc package? HOT 1
- Possible syntax simplification - type inference HOT 1
- Couldn't make it work for me HOT 1
- Switch to my new Package watch_it HOT 2
- Missing tag on GitHub HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from get_it_mixin.