Automatically resize third-party flutter widget with default sizes - flutter

I am using flutter numberpicker to build a mobile app. The default size of the widget is 50px by 100px. The size is too large for small screens. How should I make it automatically resize by specifying the right height and width?
Thanks. Any ideas and thoughts are appreciated.

You can use a combination of SizedBox and FittedBox to achieve any kind of scale manipulation of Widgets.
For your case, you can use it like this,
SizedBox(
width: 75,
child: FittedBox(
fit: BoxFit.contain,
child: NumberPicker(
value: _currentValue,
minValue: 0,
maxValue: 100,
onChanged: (value) => setState(() => _currentValue = value),
),
),
),
If you use it normally or don't give the width param in above code, tt looks like this.
But if you give a width of 75 like in the code above, it looks like this.

Related

Flutter - How to make SvgPicture.asset() take full screen inside of Slack with main parent Scaffold without Appbar

I want to make the SvgPicture take full width and height. Here is the current solution.
I have currently used double.infinity for width and height. However, I want to make it use the LayoutBuilder's constraints to make the image full width and height.
LayoutBuilder(
builder: (layoutBuilderContext, constraints) {
return Stack(
children: [
SvgPicture.asset(
'assets/images/welcome/bg-welcome-screen.svg',
fit: BoxFit.cover,
width: double.infinity,
height: double.infinity,
),
]),
})
However, that is not able to happen using constraints.maxWidth and constraints.maxHeight for sizing the SvgPicture. It takes full height but failes to take full width.
How can I size the image to full width without using double.infinity if possible. I really want it to take the full screen width and height as it is a background image for the app.
To take full size of stack use Positioned.fill, And to size the Stack widget, wrap Stack with SizedBox
SizedBox(
width: constraints.maxWidth,
height:constraints.maxHeight,
child: Stack(
children: [
Positioned.fill(
child: Text(""),
),
],
),
),
It is better to use LayoutBuilder on top level widget like scaffold's body for getting body size.
More about Stack
Have you tried using BoxFit.fill? That will fill the target width and height by distorting the image's original aspect ratio.

Flutter grey lines around expanded

I am building a flutter web app, and I want to have a carousel slider widget with images. For this I use the carousel_pro package. I want the size to be the width of my carouselslider, which takes up the whole screen's width, and then set the size accordingly, to be the exact size needed. Is there a way to do this?
Now I am settling for a less option, which looks like this:
Flexible(
child: Container(
color: CustomColours.midBlue,
constraints: BoxConstraints(maxHeight: height / 2),
//height: height / 2,
width: width,
child: Carousel(
dotBgColor: Colors.transparent,
autoplayDuration: Duration(seconds: 5),
boxFit: BoxFit.cover,
images: [
AssetImage(
'lib/assets/create-esports-poster-design-in-48-hours.png'),
//AssetImage('lib/assets/Image from iOS.jpg'),
// AssetImage('lib/assets/banner.png'),
],
),
),
),
And I know I could not add a height for a container for it to work, but since this is in a column, it has to have a height. This solution would be good for me, however now the slider has grey lines on top and below it, like this: Is there a way to 1) do what I originally wanted or 2) fix this issue? Thank you very much!

How to dynamically change container size with text quantity in flutter?

I want to create a container in flutter which changes its height according to the amount of text present in it.
If there is more text, it should cover more height, if text is less, it should cover less height.
You can use fitted Box and width of container will help you to increase height dramatically.
FittedBox(fit: BoxFit.fill,
child: Container(width: 70,
child:
Text('hello '), color: Colors.red,
)
)

Flutter - Responsive Image mapping?

Good Evening,
I have been searching for many hours and can not find a solution.
I have set a full screen image and with a Stack I have Positioned several GestureDetectors.
I have succeeded to be able to press on a GestureDetector and call a Function.
The problem is that when the screen size changes, either to a new or older phone then the Image responds and covers the full screen but the Positioned() of course stay at the same place, thus the Image mappings are not correct any more.
Is there a way to make the Positioned be responsive? or Maybe a total different way achieving the desired outcome?
Please help me :)
class Overview extends StatelessWidget {
#override
Widget build(BuildContext context) {
double sh = MediaQuery.of(context).size.height;
double sw = MediaQuery.of(context).size.width;
return Scaffold(
drawer: AppDrawer(),
body: Stack(
children: <Widget>[
Container(
height: sh,
width: sw,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/ang7.png'),
fit: BoxFit.cover)),
),
Positioned(
left: 10,
top: 50,
child: IconButton(
icon: Icon(Icons.menu),
iconSize: 30,
color: Colors.white,
onPressed: () => Scaffold.of(context).openDrawer(),
),
Positioned(
left: left,
top: top,
child: GestureDetector(
// child: Icon(Icons.add_circle),
onTap: () => Navigator.push(context, MaterialPageRoute(
builder: (context) {
return Amenities(
tText[page][0],
tText[page][1],
tText[page][2],
);
},
)),
child: Container(
height: 35,
width: 50,
color: Colors.blue,
),
));
),
Posting my comment as an answer just in case it works and there are no better answers provided. Please up vote and mark as answered if it does. :-)
You could try experimenting with MediaQuery.of to determine the size of the device (height and width) and then use those values to scale the Positioned widgets position parameters up or down from your 'baseline' sizes. In theory that should (may) match how the background image has been scaled. Would probably need to scale the size of the Positioned widgets as well.
Update regarding your comment:
Not really. What I mean is that you would need to run MediaQuery.of on the device that you are happy with the UI layout, and record that device's width and height. You then use this width and height in your app and compare these 'baseline' values with what values you get when you run the app on other devices.
So:
Divide other-device-width by baseline-device-width to get your width scaling factor.
Divide other-device-height by baseline-device-height to get your height scaling factor.
Then use these scaling factors to 'scale' the Positioned widgets width (positioned-widget-width multiplied by width-scaling-factor) and height (positioned-widget-height multiplied by height-scaling-factor) and position on the screen (you would have to play around with the positioning values).
Sounds messy but it is just a bit of simple math.
Like I say, might not work or might not be the most elegant solution. There are so many different devices out there you will never really be able to completely test this. Might need to rethink you UI. Maybe some other people have ideas around that.

Increase Flutter Radio Widget size

I am using default Flutter Radio Widget. I want to increase its size but there is no property available for it.
Tried using SizedBox with width: 50, height: 50. Didn't help.
Not want to implement a whole custom radio button. Just want to increase the default's size.
Thanks
Well you can wrap it in Transform.Scale then use the scale property to increase it.
Transform.scale(
scale: 2.0,
child: Radio(
value: 'wire',
groupValue: selectedRadio,
onChanged: (value)=>radioSelected(value),
activeColor: Color(0xffFFBD11),
),
),
I don't think this is possible without creating your own Widget.
You should have a look at this package.