Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slotWidth vs slotHeight #49

Open
vd3d opened this issue Aug 28, 2024 · 2 comments
Open

slotWidth vs slotHeight #49

vd3d opened this issue Aug 28, 2024 · 2 comments

Comments

@vd3d
Copy link

vd3d commented Aug 28, 2024

Hi,

I wish to have slots of fixed size in pixels, I have see the following parameters:

slotHeight
slotAspectRatio

I have not found any 'slotWidth' parameter. But still I have try this:

slotHeight: 32
slotAspectRatio : 1

But it is not accepted and I got an exception. So, is there a way to got a fixed size (for the slots) for width & heights ?

Thanks

@vd3d
Copy link
Author

vd3d commented Sep 1, 2024

I have found a solution, but it requires to modify the source code a little. Maybe you can add this feature officialy ? (Or not, up to you). BTW, I'm not aware of any other way of doing this.

  1. Adding slowWidth in the Dashboard class
  /// [slotWidth] determines slots width by fixed length.
  final double? slotWidth;
  1. Adding 'slotWidth' in the Dashboard constructor

  2. In method '_setNewOffset', replace
    _layoutController._setSizes(_layoutController._viewportDelegate.resolvedConstrains, h);
    with
    _layoutController._setSizes(_layoutController._viewportDelegate.resolvedConstrains, h, widget.slotWidth);

  3. In _DashboardLayoutController, replace _setSizes with this version:

  void _setSizes(BoxConstraints constrains, double vertical, double? horizontal) {
    verticalSlotEdge = vertical;
    slotEdge = (_axis == Axis.vertical ? constrains.maxWidth : constrains.maxHeight) / slotCount;
    if (horizontal != null) slotEdge = horizontal;
  }

Thanks for reading

@rohanjariwala03
Copy link
Contributor

@vd3d The SlotWidth feature can't be implemented for this package since there is no horizontal scrolling option. If we allowed you to set the width, there's a high chance that the last slot might not fit properly, leaving it with only a portion of the slotWidth. This would cause issues when placing widgets in that slot. The width of each slot is determined by the slotCount property and the total width of the dashboard you've provided.

Additionally, the slotAspectRatio helps set the height of each block when the slotHeight property is not specified. If you look at the code in dashboard.dart, you'll see there's an assertion preventing both SlotHeight and slotAspectRatio from being used simultaneously. You can only pass one of them, as both are responsible for determining the height of each slot.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants