A Widget I use often
There is a widget I use very often. It’s the Container widget. I like to add the “decoration” argument. For the “decoration” argument, I use the “BoxDecoration” widget. In the “BoxDecoration” widget, I use the “borderRadius” argument to add a circular radius.
The code below will make a yellow container that has a rounded rectangle shape.
class ConniesContainer extends StatelessWidget {@overrideWidget build(BuildContext context) {return Container(decoration: BoxDecoration(color: Colors.yellow,borderRadius: BorderRadius.circular(15),),);}}
There is one confusion I faced when using the Container widget. It’s the use of the“color” argument with the “decoration” argument and without it. In the code above, I put the “color” argument inside the “BoxDecoration” widget.
When I don’t use the “decoration” argument with the “BoxDecoration” widget, I can add the “color” argument right inside the “Container” widget like the code below.
class ConniesText extends StatelessWidget {@overrideWidget build(BuildContext context) {return Container(color: Colors.yellow,);}}
When I added the “decoration” argument and the “BoxDecoration” widget, the “Container” widget didn’t let me use the “color” argument inside the “Container” widget. I had to move it from the “Container” widget to the “BoxDecoration” widget.
I hope no one finds it confusing as I did! If you have come across this post before getting confused, that’s good! I hope I helped. Thank you for reading and have fun coding!