Is it possible to use onTap with FirebaseAnimatedList - flutter

i'm pretty new in Flutter. So i wanted to ask you guys, is it possible using FirebaseAnimatedList to make it pop another window when user presses the list item. I have a feeling that it not be possible to do it, would be great if someone could explain it.
child: FirebaseAnimatedList(
query: dbRef,
itemBuilder: (BuildContext context, DataSnapshot snapshot,
Animation<double> animation, int index) {
Map contact = snapshot.value;
return _buildContactItem(contact: contact);
},
),
Instance of onTap code snippet
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ItemPage(uid: widget.uid)),
);
},
)

If I understand u well, u want to make onPress method for each listItem?
just wrap your widget with Inkwell inside your itembuilder.
For example:
_buildContactItem(Contact contact){
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ItemPage(uid: widget.uid)),
);
},
child: yourChildWidgetsHere
}
Try this, I hope it will help you!

Related

I want a similar screen (one on top of other) like following to complete my weather app made using flutter . Can anyone please help me out?

I want this type of screen one on top of other and the previous screen should be lightly blurred or it should slightly darkens
You could use 'ModalBottomSheet' or even 'DraggableScrollableSheet' if a list is associated.
ModalBottomSheet
showModalBottomSheet(
context: context,
builder: (context) {
return Container(
// widgets
),
);
});
DraggableScrollableSheet
DraggableScrollableSheet(
builder:
(BuildContext context, ScrollController scrollController) {
return Container(
// widgets
);
},
),

The change in showModalBottomSheet is fixed by closing-opening

I have a code. I want to make changes in this code based on whether the variable is true or false. The change happens technically, but in the view, it happens when you close-open.
Codes:
InkWell(
child: Icon(Icons.check_circle, size: 30, color: importantSelected ? Colors.green : Colors.grey,),
onTap: () {
setState(() {
importantSelected = !importantSelected;
});
},
),
These codes are in showModalBottomSheet. The change is visible when I close/open the showModalBottomSheet. I want it to appear directly without turning it on and off.
you have to add StatefulBuilder and you use the new function setState
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return SingleChildScrollView()
}
)
}
);

Flutter Disable Button on ListView Builder

Hi I am trying to i have a listview.builder which renders custom card design that i create the problem is that i want to disable button on the card on which user tap but it end up disabling all the cards button
here is the code
Expanded(
child: ListView.builder(
itemCount: list.length,
itemBuilder: (context, i) {
return CardDesign(
index: i,
infolist: list,
buttonOnTap: () async {
await updateJoin(list[i].joined += 1, list[i].id);
setState(() {});
},
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsScreen(
tournamentinfo: list[i],
),
),
);
},
);
}),
the buttonOnTap Method is the one that i want to disable but only for that Specific button in the list and only for that user

How to pass context to a child widget in flutter

I have a statefull widget W1 which calls a stateless widget W2.
W2 has onTap functionality. I want to show an alert dialog in W2's onTap().
onTap:() {Alert(context: context, title:'Hi');},
I dont get any error, but no alert is shown on tap. I tried passing context as a parameter to W2 but I still dont see any dialog box.
What is the right way to show a dialog box from W2?
I am using rflutter_alert package Link
Thanks
You have to wrap your Alert(context: context, title:'Hi'); with showDialog(context: context, builder: (BuildContext context) => Alert(context: context, title:'Hi'));
Here is the cookbook sample:
Future<void> _neverSatisfied() async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('Rewind and remember'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('You will never be satisfied.'),
Text('You\’re like me. I’m never satisfied.'),
],
),
),
actions: <Widget>[
FlatButton(
child: Text('Regret'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
Anyway, for your question about how to pass context, If you are creating a Stateless or Stateful widget you dont need to pass the context, you can get it from build(BuildContext context) {}.
Adding .show() in end solved it.
onTap:() {Alert(context: context, title:'Hi').show();}
Its clearly documented in rflutter_alert package, but I somehow missed it.
Pass the context in the function call in onTap:
onTap:(context) {Alert(context: context, title:'Hi');},

how to prevent flutter showBottomSheet from being dismissed by dragging down?

I am using showBottomSheet in flutter to show a persistent bottom sheet. how can I prevent flutter showBottomSheet from being dismissed by dragging down?
I have added my code below. you can place a rawmaterialbutton and with onpressed call this function.
void itemChooser(
{int currentItemCount, String name, callBack, BuildContext context}) {
int chosen = 0;
showBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
height: 500,
color: Colors.white,
);
});
}
Just wrap your child with GestureDetector and set onVerticalDragStart: (_) {},
showBottomSheet(
context: context,
builder: (context) => GestureDetector(
child: *your_widget*,
onVerticalDragStart: (_) {},
),
);
Set enableDrag property of BottomSheet to false its true by default
BottomSheet(
enableDrag: false,
builder: //builder
),
Refer here for more info on BottomSheet
If you use showModalBottomSheet, simply use enableDrag property:
showModalBottomSheet(
context: context,
builder: (context) => yourWidget,
enableDrag: false,
);