FractionallySizedBox (Flutter Widget of the Week)
Why Stack Overflow recommends it
Stack Overflow users link it when answering Flutter layout questions about percentage-based sizing, responsive widths, and making FractionallySizedBox behave inside a Row or Column.
Recommended by 3 people across 3 different months, 2019 to 2022.
What it is
A one-minute Flutter 'Widget of the Week' episode from the official Flutter channel explaining FractionallySizedBox, which sizes its child to a fraction of the available space. It briefly shows how it works and mentions pairing it with Flexible inside rows and columns.
What people said
Recommends k dimitrov · 2019-12 · Stack Overflow · on “Using FractionallySizedBox in a Row”
As explained in the "FractionallySizedBox (Flutter Widget of the Week)" video by the Flutter team, the FractionallySizedBox needs to be wrapped in Flexible widget, "so it plays well with a row or a column". Reference: [this video] This should be the solution to the original question, formatted below: Container( height: 24.0, color: Colors.black, child: Row( children: [ Flexible( child: FractionallySizedBox( heightFactor: 1, widthFactor: 0.25, child: Container(color: Colors.orange), ), ), Flexible( child: FractionallySizedBox( heightFactor: 1, widthFactor: 0.15, child: Container(color: Colors.green)), ), Flexible( child: FractionallySizedBox( heightFactor: 1, widthFactor: 0.05, child: Container(co
Recommends Hudson Kim · 2020-06 · Stack Overflow · on “Should I use absolute pixel values in my Flutter widgets, or should I scale them to the screen?”
I would recommend you to scale widgets based on the size of the screen. This allows your application to be more flexible and adjust to various platforms and sizes such as large tablets or small phones. In order to do this, I recommend you to use the widget FractionallySizedBox which allows you to size widgets using a percentage of the screen size. For example, if you want a button widget to fill up 50 percent of a screen's width you can use the following code: Container( alignment: Alignment.center, child: FractionallySizedBox( widthFactor: 0.5, child: FlatButton( onTap: () {}, child: Text("PRESS HERE") ) ) ) This code creates a button positioned in the center of the screen with a width of 5
Recommends landyrev · 2022-11 · Stack Overflow · on “My costume widget is not showing in a Column”
You need to wrap your widget inside the Flexible one, like this: class _HomePageState extends State<HomePage> { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: new Text("hello"), ), body: new Container( child: new Column( children: [ new Flexible(child: Costume()), new Chart()], )), ), ); } } CHeckout FractionallySizedBox (Flutter Widget of the Week) [this video] video
Cites Magesh Pandian · 2019-09 · Stack Overflow · on “Flutter LinearLayout weight alternative”
We can use FractionallySizedBox [LINK] widget to give weight sum for both width and height. FractionallySizedBox( heightFactor: .5, widthFactor: 1.0, alignment: Alignment.topCenter, child: child, ) For more info: Link [this video]
Cites Taufik Nur Rahmanda · 2019-09 · Stack Overflow · on “Making Responsive screen with flutter”
you can use FractionallySizedBox with widthFactor or heightFactor , see: [this video] and for orientation you can wrap your widget with OrientationBuilder : [LINK]
Cites Sanjayrajsinh · 2019-12 · Stack Overflow · on “Sizing elements to percentage of screen width/height”
There is many way to do this. 1. Using MediaQuery : Its return fullscreen of your device including appbar,toolbar Container( width: MediaQuery.of(context).size.width * 0.50, height: MediaQuery.of(context).size.height*0.50, color: Colors.blueAccent[400], ) [LINK] 2. Using Expanded : You can set width/height in ratio Container( height: MediaQuery.of(context).size.height * 0.50, child: Row( children: <Widget>[ Expanded( flex: 70, child: Container( color: Colors.lightBlue[400], ), ), Expanded( flex: 30, child: Container( color: Colors.deepPurple[800], ), ) ], ), ) [LINK] 3. Others Like Flexible [LINK] and AspectRatio [LINK] and FractionallySizedBox [this video]