Last active
April 14, 2018 18:54
-
-
Save Blasanka/a06594e28af88a156c7343eef96a8d88 to your computer and use it in GitHub Desktop.
Image is here: https://i.stack.imgur.com/ldYUY.png This example code demonstrate: How to add two rectangles, one is take 60% of the screen while other one take 40%. You can change these according to as you want. And this example explain how to get width of the device screen and how to make your component flexible without fixed values. Also I hav…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//with dart 2 new and const keywords are optional | |
void main() => runApp(new MaterialApp(home: new HomePage(),)); | |
class HomePage extends StatelessWidget { | |
final text = new Text('Text here', style: new TextStyle(fontSize: 50.0),); | |
final margin = const EdgeInsets.only(bottom: 10.0, right: 10.0, left: 10.0); | |
final backColor = Colors.lightGreen; | |
@override | |
Widget build(BuildContext context) { | |
var width = MediaQuery.of(context).size.width; // Using this line I got the device screen width | |
return new Scaffold( | |
body: new SafeArea(//I didnt add appbar. this will add necessary padding for status bar. | |
child: new Column( | |
children: [ | |
new Expanded( | |
flex: 2, | |
child: new Container( | |
width: width /1.5, // this will give you flexible width not fixed width | |
margin: margin, // variable | |
color: backColor,// variable | |
child: new Column( | |
children: <Widget>[ | |
new Expanded( | |
flex: 1, | |
child: new Container( | |
alignment: Alignment.topCenter, | |
child: text, //varaible above | |
), | |
), | |
new Expanded( | |
flex: 1, | |
child: new Container( | |
alignment: Alignment.bottomCenter, | |
child: text, //variable above | |
), | |
), | |
], | |
), | |
), | |
), | |
new Expanded( | |
flex: 3, | |
child: new Container( | |
width: width /1.5, // this will give you flexible width not fixed width | |
margin: margin, //variable | |
color: backColor,//variable | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment