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.
Related
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
in my app I often need a list of objects that I get with 3 StreamBuilders. I want to avoid repeating those StreamBuilders every time.
So I tried to do a Stateful Widget that contains my 3 StreamBuilders with a Widget child argument returned by the last StreamBuilder.
But it doesn't work. The datas are not communicated to the child Widget.
What is the good way to do it please?
Click on StreamBuilder()
Then right click => select Refactor form the options => Click on Extract Flutter Widget
Now create a file with any name like streambuilder_helper.dart
Cut and paste the Extracted Widget in this file. Make sure to import material.dart
Now suppose you want to use this anywhere in your app just import the file streambuilder_helper.dart
While creating this flutter widget if you want to use this anywhere make sure to create several finals like
final myStream;
and then suppose the name of the flutter widget you defined is myStreamBuilder() then you have to create
myStreamBuilder({}); inside the flutter widget
and define this myStream final in it
myStreamBuilder({this.myStream});
and finally replace the hard coded code with your final in the StreamBuilder.
Can you directly obtain the result of the emoticon image searched in the input method? In flutter, such as Sogou input method, as shown below
like this
I am getting data from firestore and wants to print out using map but it is giving an error
type 'List<Widget>' is not a subtype of type 'Widget'
My code is look like this:
return SingleChildScrollView(
child: snapshot.data.documents[i].data['comments']
.map<Widget>((values) => Text(values['name']))
.toList());
SingleChildScrollView according to its name expects single child. Its child property is defined to be of type Widget.
Method .toList also according to its name returns List which is apparently not a Widget.
What you can do here is to either use ListView instead of SingleChildScrollView or use Column, ListBody as well as any other single child wrapping your desired List<Widgets> into it. Refer to examples on SingleChildScrollView page for more information.
We have a lot of State management solutions like providers and BLoC pattern. But, why do we need them?. why can't I create a file called 'data.dart' and import this file(data.dart) wherever i need, and make changes to the variables and objects in this file(data.dart)? Does this pattern has any downsides?
State management solutions are needed for datas that changes.
Imagine having data.dart file that has a variable
String text = 'abc';
And you have a Text() widget called TextA that takes in text variable as input.
This widget would initially display abc
now you have this function called
void changeText(){
text = 'cba';
}
how would this function tell TextA to rebuild because the value of text has already been changed?
of course you can use setState((){}); as long as the function is part of TextA,
but what if the Widget is ButtonA?
similar to StatefulWidget you can change the value using setState() to rebuild the widgets but what if you want a button in child widget that change the value in parent widget ? here you need to use provider to get full control.
Note: this is as example but it has multiple uses. you can use it with Firebase auth or cloud Firestore.