Passing builder atribute to a isolate widget on dart - flutter

I am trying to pass a index attribute from an api to a image widget which show the network image, i get the undefined identifier error

I think you have missed to pass the index from MoviesList() widget to MovieCard Widget

Related

How to add widget parameters while passing it through json data?

As shown in the image i am trying to passing a json field value while using navigator.push in MaterialPageRoute.
Now how i can pass a argument value so that i can use that in the widget in the later screen?
I have searched but found namedRoute as a solution but as i am passing widgets through json that's not an option.

My ValueNotifier is not Working properly, why?

I have a GestureDetector inside a ListView and a CustomFilter widget in my Scaffold.
When I filter or change me showList in CustomFiter Widget it seems to be updated because I print the correct value from my CustomValueNotifier.
When it comes to my parent widget which is supposed to show my showList inside the GestureDetector the value is not updated at all and is at all times an empty list.
So the problem seems to be between the connection of my parent widget which hold both the filter widget, which upadtes the list, and my CustomValueNotifier, which takes the updated value but as I said before does not provide it at the widget.
Right now I also do the onnection with getter and setter so in the code im goin to show the showList will be taken the correct value from the getShowList() method. The problem is it doesnt change when the filter is being activated, on change of each filter, but after that when i press somewhere inside the gesturedetector again.
I have tried Change Notifier,Value Notifier, Provider does not seem to be what i can use in this example, setState but of course it updates on click in gestureDetector later

Flutter - Use both GlobalKey and ValueKey for a custom widget

I have a custom widget class which I need to render it into a bitmap icon using BitmapDescriptor, so I need to define it's GlobalKey.
GlobalKey<TheWidgetState> globalkey = GlobalKey<TheWidgetState>();
#override
Widget build(BuildContext context) {... TheWidget(globalkey) ...}
...
//Somewhere. Has nothing to do with the issue
BitmapDescriptor.fromBytes((await (await (globalkey.currentContext?.findRenderObject() as RenderRepaintBoundary).toImage()).toByteData(format: ui.ImageByteFormat.png))!.buffer.asUint8List());
...
Before doing that, I also need to update the state of the widget before render it like in above code, without changing it's position on the tree. So I also need to define it's ValueKey to do that.
I'm still confused about the purpose of every other key types in Flutter. But as for now I need both the purpose of GlobalKey and ValueKey for my widget. Since both need to be defined with variable name key, I have neither an idea on how to set the widget with both keys nor an answer which key serve both purposes that I need.
Greatly appreciate the help.

Method returning different StatefulWidgets not updating when different widget is returned

I have a method that returns one of two stateful widgets, based on the value of an enum. However, even though I can see via the debugger that the "correct" widget is being returned, the UI only ever shows the first one that is rendered. It seems the state object is somehow being shared across different instances of the widget, or I'm missing something.
Widget _buildInfoCard(LoginStatus status) {
switch(status) {
case LoginStatus.LOGIN_FAILED:
return InfoCard("Login failed, please check your username and password.");
default:
return InfoCard("Please login with your username and password");
}
}
I expect that the displayed infocard will have the text that corresponds to the text of the returned info card, but the default case always presents. I've stepped through the code, the correct widget is returned, and the default widget is not returned after that, so it should be displayed, but does not.
EDIT:
The _buildInfoCard method gets called inside of a streambuilder.
You need to give each instance of your StatefulWidget a key otherwise they may share state, something like this:
Widget _buildInfoCard(LoginStatus status) {
switch (status) {
case LoginStatus.LOGIN_FAILED:
return InfoCard(
key: ValueKey(status),
message: "Login failed, please check your username and password.",
);
default:
return InfoCard(
key: ValueKey(status),
message: "Please login with your username and password",
);
}
}
Very good article about why we need keys here: https://medium.com/flutter/keys-what-are-they-good-for-13cb51742e7d
For anyone with the same issue - follow the link provided by Jordan Davies, then watch episode 2 of Flutter 101 on YouTube for more information.
The issue is that as you construct your widget tree, the flutter framework translates those widgets into elements, which it then uses to render the UI.
When the flutter framework is constructing the element tree, it looks at each widget and compares the widget type to the element type at a given position in the tree. If the types are the same, flutter may re-use the element.
Stateful widgets have a long-lived state object, they may not get deleted with the wrapping element when a new one added to the element tree. In this case, the newly returned widget may use an existing state object from a previously rendered stateful widget.
The solution is as Jordan suggested, use keys to prevent this from hapenning, or use stateless widgets. There are other methods on Stateful widgets that may work as well, but Jordan's answer best addresses my expectations.

Create own widget that can interpret html inside

I want to create own widget that will be able to interpret the text between start and end tag, eg:
<p1:Btn ui:field="open" >Open</p1:Btn>
Now the UI binder throws error:
Unexpected text in element: "Open" Element <p1:Btn ui:field='open'> (:44)
I supose that the widget have to be somehow marked to allow elements inside.
The second thing is how read the element between tags.
Your widget needs simply implement the HasText interface.