Comments (3)
_It looks like you're trying to position a PopupMenu in Flutter using showMenu with a RelativeRect. However, the positioning you've described might not work as expected because RelativeRect.fromLTRB sets the left, top, right, and bottom offsets of the rectangle relative to the parent widget's edges, but it doesn't take into account the menu's size.
To achieve the desired separation from the bottom right corner, you can calculate the position dynamically based on the menu's size. Here's an updated version of your code that should position the menu 20 units from the bottom and right edges:_
CustomElevatedButton(
icon: Icons.more_vert,
onPressed: () {
final RenderBox button = context.findRenderObject() as RenderBox;
final Offset buttonPosition = button.localToGlobal(Offset.zero);
final double screenHeight = MediaQuery.of(context).size.height;
final double screenWidth = MediaQuery.of(context).size.width;
final double dx = screenWidth - buttonPosition.dx - 20;
final double dy = screenHeight - buttonPosition.dy - 20;
showMenu(
context: context,
position: RelativeRect.fromLTRB(dx, dy, 0, 0),
items: const [
PopupMenuItem(
value: 'Añadir',
child: Text('Añadir'),
),
PopupMenuItem(
value: 'Filtrar',
child: Text('Filtrar'),
),
],
elevation: 8.0,
).then((choice) {
if (choice != null) {
if (choice == 'Añadir') {
showDialogMethod();
} else if (choice == 'Filtrar') {
// Handle 'Filtrar' choice
}
}
});
},
)
This code calculates the position of the button relative to the screen and then adjusts the menu's position accordingly to ensure it is 20 units from the bottom and right edges.
``
from flutter.
You're right!! The menu have been placed 20 units from the bottom edges. The 20 units of the right edge have not worked in this way, what I have done is to collect both options for it to work correctly:
CustomElevatedButton(
icon: Icons.more_vert,
onPressed: () {
final RenderBox button = context.findRenderObject() as RenderBox;
final Offset buttonPosition = button.localToGlobal(Offset.zero);
final double screenHeight = MediaQuery.of(context).size.height;
final double screenWidth = MediaQuery.of(context).size.width;
final double dx = screenWidth - buttonPosition.dx;
final double dy = screenHeight - buttonPosition.dy - 150;
showMenu(
context: context,
position: RelativeRect.fromLTRB(dx, dy, 20, 0),
items: const [
PopupMenuItem(
value: 'Añadir',
child: Text('Añadir'),
),
PopupMenuItem(
value: 'Filtrar',
child: Text('Filtrar'),
),
],
elevation: 8.0,
).then((choice) {
if (choice != null) {
if (choice == 'Añadir') {
showDialogMethod();
} else if (choice == 'Filtrar') {
// Handle 'Filtrar' choice
}
}
});
},
)
Thank you very much!!!!
from flutter.
Hi @Rafapeerez, has your issue been resolved?
from flutter.
Related Issues (20)
- RangeSlider : bad rounded value on 55 HOT 4
- Cherry picks to the engine require formatting HOT 5
- [Impeller] Different blur effect when using BorderRadius.only HOT 4
- mac-10 lost external connection phone device. HOT 2
- mac-7 and mac-24 lost external connection phone device. HOT 2
- Blank/empty UI on second run of app in Android emulator. HOT 22
- [pigeon] [Mac-14] runPigeonIntegrationTests timeout in CI on macOS 14 HOT 6
- mac-23 lost external connection phone device. HOT 2
- [webview_flutter] [flutter 3.22.1] iOS textfield cannot call up keyboard after exiting webview_flutter page in flutter 3.22.1, no problem in 3.19.6 HOT 11
- Flutter 3.22.0 -- iOS crash on app launch: 0x0000000108967408 NativeCanvas._restore$Method$FfiNative + 124 HOT 36
- Can't use shadow build with `led` in staging pool for some engine tests HOT 4
- RichText is not following Android system font size HOT 7
- [go_router]: StatefulShellRoute does not persist when navigating to a new screen after 12.x.x HOT 5
- mac-3 lost external connection phone device. HOT 2
- [go_router] ability to have a default pop to HOT 7
- [Impeller] Android: Impeller opt-out via the command-line and manifest options must work.
- Machine 'flutter-devicelab-linux-38' might be in bad state and may need to be quarantined HOT 2
- Allow safely probing for surrounding `_InheritedNestedScrollView` HOT 2
- [Impeller] backdrop blurs have bad performance compared to Skia when only covering a small region of the screen. HOT 1
- `flutter build ipa` fails: Command line name "app-store" is deprecated. Use "app-store-connect" HOT 7
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 flutter.