I have a stackview like this
I pinned the stackview like this:
Top: 200, Leading: 20, Trailing: 20, Bottom: 200
I want the stackview to be fixed to this size for every screen size, how do I achieve this?
Add leading, trailing, center vertically and aspect ratio 1:1 constraint to main StakeView.
Also, Add equal widths and equal heights constraint to each button.
Output :
Choose the Stack View and add Aspect Ration :
Then double click on the Aspect Ration around the Stack View and make the Multiplier 1:1 :
Then you can add Trailing and Leading constrains + Center Vertically in Safe Area.
Related
When using the Positioned widget in flutter, can I specify the top and bottom parameter as a percentage of the stack instead of exact pixels?
I have an Idea! I don't know, how do you like it.
You can't use percentages directly for exact pixels.
but you can use MediaQuery to use percentages.
final size = MediaQuery.of(context).size; //this var has 100% of your screen
now you can use a percentage of your screenSize in the top, bottom, right, and left properties.
like
top: size.height / 2, //it will be divide your screenHeight by 2 means 50%
I have 2 suggestions :
first :
in the Stack Widget, there is an alignment property, where you can choose a value from the Alignment enum to align the Positioned widget
you can also wrap Positioned widget with Align widget
if this doesn't fit in your case
in that alignment property you can use Alignment constructor to specify a y and x values to align your widget, so in example :
alignment: Alignment(0, 0)
will center your widget
alignment: Alignment(-1, -1)
will align your widget to the left top
alignment: Alignment(1, 1)
will align your widget to the right bottom
with this, you can use those between those values to get into a specific alignment
with multiplying by your calculated percentage to get into specific align based on %
this is the cell design design img
for pic
width = height = 40, top = 15, leading = 15
here for name rose d i have given constraint
width = 60, top = 15, leading = 10
for place a bid on the request label
top = 15, leading = 5
for trip for few days label
top = 15, leading = 5, trailing >= 20
for dummy caption shoe here label
trailing = 20, leading to image = 10, top to rose d = 5 and label lines = 0
for 46 mins ago label
top and leading to dummy caption.. lable = 10, trailing >= 20
i don't want to give row fixed height.. because dummy caption label may increase..
now rows not showing in tableview.. only if i give fixed height then only showing
here where i go wrong with constraints.. so i not getting rows in tableview, please guide me
if i give bottom constraint to lowest label and if i add more text to middle label then coming like this design and constraint of middle label img
You have not set any bottom constraints, therefore the layout doesn't know how to anchor the bottom of the cell to your UI elements.
Set constraints from the lowest element to the bottom of the cell's content view, or more flexibly set greater or equal to constraints from all lower elements so you don't need to worry about the number of lines in your labels.
However, I think a better approach would be to use a single label with an attributed string to provide the colouring. This will be more flexible and ensure the spacing between words looks natural.
In flutter charts, the horizontal chart automatically stretches according to the height of the screen. Is there any way through which I may fix the height of the bars so that it may not stretch to the entire screen?
Simple add your chart in the ConstrainedBox like this -
ConstrainedBox(
constraints: BoxConstraints.expand(height: 200.0), // give the height according to you
child : Your_Chart_here(), // your chart here
),
You can try to wrap BarChart in to SizedBox (to set size), wrapped with SingleChildScrollView (to scroll it).
In pseudocode
- SingleChildScrollView
- SizedBox
- charts.BarChart
Flutter
SingleChildScrollView(
child: SizedBox(
height: 2000,
child: HorizontalBarLabelChart(
getData(),
),
),
),
Size calculation
Height of the SizedBox can be calculated base on number of data, e.g.:
numerOfElements * 50
Before
For 100 elements
After
For 100 elements (so height is 5000 because 100 * 50)
I have created a scrollable area and i am trying to add a scrollbar underneath the images (the blue scrollbar in the linked image)
Code that i currently have for the scrollable area.
scroll = new ScrollComponent
opacity: 1.00
shadowBlur: 0
scroll.size = screen
Info.parent = scroll.content
scroll.scrollVertical = false
Scroll
I think you're trying to make a scrollbar that moves with the scrolling and shows how far along the user has scrolled, right?
Here's some code how to do that:
scrollbar.parent = scroll
# First make the width of the scrollbar relative to the size of the content.
scrollbar.width = (scroll.width / scroll.content.width) * scroll.width
# When the scroll is moved
scroll.onMove ->
# Calculate the width that we should scroll over
width = scroll.content.width - scroll.width
# Calculate the percentage that has currently been scrolled
percentage = scroll.scrollX / width
# Calculate how much space there for the scrollbar to move in
freeSpace = scroll.width - scrollbar.width
# Set the position of the scrollbar relative to the free space and the percentage scrolled
scrollbar.x = freeSpace * percentage
A full example is here: https://framer.cloud/QtcLD
I'd like to be able to detect when a UITextfield overflows it bounds.
I want to detect Horizontal overflow (since there is only 1 line).
I was thinking about counting the amount of characters and multiplying that with a default value for the letter width and see if that fits inside the textfield bounds but that wouldn't work due too the letter having different widths.
I am aware of adjustsFontSizeToFitWidth but I want to increase the width of the textfield instead of decreasing the font size.
Here is the code which first calculates the size of the text and then compares it to the label size:
let textSize: CGSize = self.label.text!.sizeWithAttributes([NSFontAttributeName: self.label.font])
let isOverflowing: Bool = textSize.width > self.label.frame.size.width