How to make pop up like this - flutter

Do you guys know how to make pop up that small and appear below icon like this? I have made it with AlertDialog, but the pop up is on the center of the screen and too big.

Using this code you can show the menu where you need
Function
void showPopUpMenuAtTap(BuildContext context, TapDownDetails details) {
showMenu(
context: context,
position: RelativeRect.fromLTRB(
details.globalPosition.dx,
details.globalPosition.dy,
details.globalPosition.dx,
details.globalPosition.dy,
),
items: const [
PopupMenuItem<String>(value: '1', child: Text('menu option 1')),
PopupMenuItem<String>(value: '2', child: Text('menu option 2')),
PopupMenuItem<String>(value: '3', child: Text('menu option 3')),
],
).then((value) {
if (value == null) return;
if (value == "1") {
//code here
log("message", name: value);
} else if (value == "2") {
//code here
log("message", name: value);
} else if (value == "3") {
//code here
log("message", name: value);
}
});
}
You can call like this
GestureDetector(
child: const Icon(Icons.menu),
onTapDown: (details) => showPopUpMenuAtTap(context, details),
),

PopupMenuButton from Flutter sdk
https://api.flutter.dev/flutter/material/PopupMenuButton-class.html
You can profile ShapeBorder as RoundedRectangleBorder.

what you need is popupmenu not AlertDialog here the documantain of popupmenu
with the feature shape, you could play with the shape and size ...etc

Related

CheckedPopupMenuItem: How to position the checkmark to the right?

I have a standard PopupMenuButton with CheckedPopupMenuItems:
PopupMenuButton<String>(
icon: const Icon(Icons.sort_by_alpha),
onSelected: (String result) {
if(result == optionOne){ doSomething(); }
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
CheckedPopupMenuItem<String>(
value: optionOne,
child: Text("optionOne"),
),
),
],
),
The checkmark for which item is selected appears to the left- I'd like to have it on the right, but can't find how to do this.
EDIT:
Is the only way really to not use CheckedPopupMenuItem completely and build the functionality myself?

buttons in multiple lines - Flutter

I want to list text button in the way represented in "Booking APP" filter
I've tried a Row, ListView and GridView, i want something like a row in multiple line.
the code
SingleChildScrollView(
padding: FxSpacing.x(24),
scrollDirection: Axis.horizontal,
child: Row(
children:
['Any', '1', '2', '3', '4', '5'].map((element) {
return InkWell(
onTap: () {
setState(() {
if (estateHomeController.selectedBathRooms.contains(element)) {
estateHomeController.selectedBathRooms.remove(element);
} else {
estateHomeController.selectedBathRooms.add(element);
}
});
},
child: SingleBath(
bath: element,
selected: estateHomeController.selectedBathRooms.contains(element),
));
}).toList()),
),
Try Wrap widget
Wrap(
children: ['Any', '1', '2', '3', '4', '5']
.map(
(e) => InkWell(
onTap: () {
setState(() {
if (estateHomeController.selectedBathRooms.contains(element)) {
estateHomeController.selectedBathRooms.remove(element);
} else {
estateHomeController.selectedBathRooms.add(element);
}
});
},
child: SingleBath(
bath: element,
selected: estateHomeController.selectedBathRooms.contains(element),
)),
)
.toList(),
spacing: 8,
runSpacing: 8,
),
Material chips might also suit your use case since you are looking at using these chips as filters to show different results

Flutter Dynamic PopupMenu Content

I'm trying to create a menu that has a 'load more' functionality. From an interface perspective, PopupMenuButton has worked nicely, but I've been unable to dynamically refresh its content.
I'm using redux and I can successfully dispatch the action to fetch more, and the store is updated, but I don't see the change until I close the menu and re-open it, despite wrapping the PopupMenuButton in a StoreConnector. I also have a check for fetchInProgress that should be changing the bottom 'more' item to a spinner while the fetch is in progress, but that state change isn't noticed either.
I'm relatively new to Flutter so I'm wondering if I'm missing something.
Gif of the behavior
#override
Widget build(BuildContext context) {
return StoreConnector<AppState, _ViewModel>(
converter: (store) => _ViewModel.fromStore(store, oneOnOneId),
builder: (ctx, vm) => PopupMenuButton(
onSelected: (callback) => callback(),
icon: Icon(Icons.expand_more),
itemBuilder: (_) =>
[...vm.pastOneOnOnes.map((m) {
return PopupMenuItem(
child: Center(child: Text(DateFormat('MM/dd/yyyy').format(m.meetingDate))),
value: () => {
Navigator.of(context).pushReplacementNamed(routeName,
arguments: {
'meetingId': m.id
})
}
);
}).toList(),
PopupMenuItem(
enabled: false,
child: Container(
height: 40,
width: double.infinity,
child: vm.fetchInProgress ?
Center(child: CircularProgressIndicator()) :
InkWell(
onTap: () => vm.fetchPastOneOnOnes(oneOnOneId, start: vm.pastOneOnOnes.length + 1),
child: Center(
child: Text('More', style: TextStyle(color: Colors.black))
)
),
),
value: null
)
]
),
);
}
}
You need to update the state when you make a change. When you call => vm.fetchPastOneOnOnes wrap it with setState :
onTap: () {
setState(){
vm.fetchPastOneOnOnes(...);}},

Flutter: disable ExpansionTile

I have an ExpansionTile that checks if the user is allowed to enable it:
ExpansionTile(
tilePadding: widget.rent ? EdgeInsets.all(0) : null,
onExpansionChanged: (bool value) {
if (_canCreateBill) {
setState(() {
_billable = value;
});
} else {
return Navigator.of(context)
.pushNamed('/invoice-details')
.then((val) async {
await _getBillingInfo();
setState(() {
_billable =
_canCreateBill;
});
});
}
widget.onSwitchChange(value);
},
initiallyExpanded: _billable,
title: Text(translate('expense.create_invoice')),
subtitle: Text(translate('expense.create_invoice_info')),
trailing: IgnorePointer(
child: Switch(
value: _billable,
onChanged: (_) {},
),
),
children: [
Visibility(
visible: _canCreateBill,
child: _billingInfo(),
),
],
);
Happy path:
Here we have _canCreateBill which controls if the user can enable the switch. If the user clicks and he's not allowed, I moved him to a page to add some info. After adding that info, he comes back and the switch is enable.
Problem:
The user can go back without adding any info. The switch will be disable but the ExpansionTile will be active because we already clicked on it:
How can check for this also? Can we disable the ExpansionTile or force a click somehow?
This option is not a solution:
IgnorePointer(
ignoring: true,
child: ExpansionTile()
)

How to get Radio to work on flutter when using dynamic object?

I'm new to flutter and I have issues with Radio.
I got it to work perfectly when using the "regular" method:
int _groupValue=-1;
...
...
child: Align(
alignment: Alignment.center,
child: Column(
children: <Widget>[
RadioListTile(activeColor: Colors.black,
groupValue: _groupValue,
value: 1,
onChanged: (value) { setState(() {
_groupValue=value;
}); },
title: Text("a"),
),
RadioListTile(activeColor: Colors.black,
groupValue: _groupValue,
value: 2,
onChanged: (value) { setState(() {
_groupValue=value;
}); },
title: Text("b"),
),
],
),
),
Since I'm using data from API to create the radio buttons I've changed this code to this:
child: Align(
alignment: Alignment.center,
child: children: radioListView
),
),
and on click of a button i call async method to download the data from the API and like this :
void getApiData() async {
...
...
...
setState() {
var radioListView = List<RadioListTile>();
for (Map<String, dynamic> c in apidata)) {
radioListView.add(new RadioListTile(
groupValue: _groupValue,
value: c['option_value'],
title: c['title'],
onChanged: (value) { setState(() {
_groupValue=value;
});
),
));
}
}
}
using the first code it works but using the second code I just get to see the items but nothing happens when I click on the radio buttons (although the onchanged does trigger because I tried to print the value and it's fine)
what am I doing wrong?
I found the solution here:
https://www.didierboelens.com/2018/05/hint-5-how-to-refresh-the-content-of-a-dialog-via-setstate/
The problem was that I had to seperate the widgets and create another stateful widget for the radio