Flutter Create Rounded Corner Rectangle Square Shape Container Example

There are two famous shapes for solving and defining math equations Rectangle and Square shape. In flutter its easy to create simple rectangle and square shape using container widget but they have sharp edges and the corner is sharp but using BoxDecoration property of box decoration we can easily make the edges rounded. The box decoration has a sub property named as BorderRadius.all() which supports double value and used to make the edges rounded in Container widget. So in this tutorial we would Flutter Create Rounded Corner Rectangle Square Shape Container Android iOS Example Tutorial.

Contents in this project Flutter Create Rounded Corner Rectangle Square Shape Container Android iOS Example Tutorial:

1. Import material.dart package in your app's main.dart file.

import 'package:flutter/material.dart' ;

2. Create void main runApp() method and here we would call our main MyApp class.

void main ( ) = > runApp ( MyApp ( ) ) ;

3. Create our main MyApp class extends with Statelesswidget.

class MyApp extends StatelessWidget {

}

4. Create Widget build area in MyApp class. Now we would make the Scaffold widget-> Center widget -> Column widget. We would use the Column widget to put multiple children.

Widget build ( BuildContext context ) {

return MaterialApp (

home : Scaffold (

backgroundColor : Colors . white ,

body : Center (

child : Column (

mainAxisAlignment : MainAxisAlignment . spaceEvenly ,

children : < Widget > [

] , )

)

)

) ;

}

5. Creating a Container widget in Column widget. This is our Rectangle shape view.

Container (

height : 150.0 ,

width : 300.0 ,

color : Colors . transparent ,

child : Container (

decoration : BoxDecoration (

color : Colors . green ,

borderRadius : BorderRadius . all ( Radius . circular ( 10.0 ) ) ) ,

child : new Center (

child : new Text ( "Rounded Corner Rectangle Shape" ,

style : TextStyle ( color : Colors . white , fontSize : 22 ) ,

textAlign : TextAlign . center , ) ,

) ) ,

) ,

6. Creating another Container widget in Column widget. This is our Square view . The main difference between square and rectangle is that square shape has same width and height and in rectangle shape the width is twice than height of view.

Container (

height : 150.0 ,

width : 150.0 ,

color : Colors . transparent ,

child : Container (

decoration : BoxDecoration (

color : Colors . green ,

borderRadius : BorderRadius . all ( Radius . circular ( 10.0 ) ) ) ,

child : new Center (

child : new Text ( "Rounded Corner Square Shape" ,

style : TextStyle ( fontSize : 22 , color : Colors . white ) ,

textAlign : TextAlign . center , ) ,

) ) ,

) ,

7. Complete source code for main.dart file:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

import 'package:flutter/material.dart' ;

void main ( ) = > runApp ( MyApp ( ) ) ;

class MyApp extends StatelessWidget {

@ override

Widget build ( BuildContext context ) {

return MaterialApp (

home : Scaffold (

backgroundColor : Colors . white ,

body : Center (

child : Column (

mainAxisAlignment : MainAxisAlignment . spaceEvenly ,

children : < Widget > [

Container (

height : 150.0 ,

width : 300.0 ,

color : Colors . transparent ,

child : Container (

decoration : BoxDecoration (

color : Colors . green ,

borderRadius : BorderRadius . all ( Radius . circular ( 10.0 ) ) ) ,

child : new Center (

child : new Text ( "Rounded Corner Rectangle Shape" ,

style : TextStyle ( color : Colors . white , fontSize : 22 ) ,

textAlign : TextAlign . center , ) ,

) ) ,

) ,

Container (

height : 150.0 ,

width : 150.0 ,

color : Colors . transparent ,

child : Container (

decoration : BoxDecoration (

color : Colors . green ,

borderRadius : BorderRadius . all ( Radius . circular ( 10.0 ) ) ) ,

child : new Center (

child : new Text ( "Rounded Corner Square Shape" ,

style : TextStyle ( fontSize : 22 , color : Colors . white ) ,

textAlign : TextAlign . center , ) ,

) ) ,

) ,

] , )

)

)

) ;

}

}

Screenshot:

Also Read: