What creates rounded corners?
borderRadius in BoxDecoration creates rounded corners.
The most versatile widget in Flutter
Passing the Quiz & Exercises is mandatory to earn FX and proceed. If you fail, try again to gain the required FX, then the Proceed button will become available.
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
The Container widget is one of the most versatile building blocks in Flutter. It can add padding, margins, colors, borders, rounded corners, shadows, and gradients to any child widget. Think of it as a customizable box that wraps around other widgets.
1// --- Container: A Box for Everything ---23Container(4// Size5width: 200, // Box width6height: 100, // Box height78// Spacing inside the box9padding: EdgeInsets.all(16), // Space inside1011// Spacing outside the box12margin: EdgeInsets.symmetric(13horizontal: 20, // Left & right margin14),1516// Visual styling17decoration: BoxDecoration(18color: Colors.white, // Background color19borderRadius: BorderRadius.circular(12), // Rounded corners20boxShadow: [ // Drop shadow21BoxShadow(22color: Colors.black26, // Shadow color23blurRadius: 10, // Shadow blur24offset: Offset(0, 4), // Shadow position25),26],27),2829// Content inside the container30child: Text('Hello'),31)
EdgeInsets is the class used to define spacing inside (padding) or outside (margin) a widget. Flutter provides several convenient constructors to cover common spacing patterns.
1// --- EdgeInsets: Specify Spacing ---23// Same spacing on all sides4EdgeInsets.all(16) // 16px everywhere56// Horizontal & Vertical7EdgeInsets.symmetric(8horizontal: 20, // Left & Right = 209vertical: 10, // Top & Bottom = 1010)1112// Only specific sides13EdgeInsets.only(14left: 10,15top: 20,16)1718// All four sides separately19EdgeInsets.fromLTRB(10, 20, 10, 20) // Left, Top, Right, Bottom
BoxDecoration provides multiple ways to style a Container. You can use solid colors, gradients, images, borders, and shadows. Here are the most common patterns.
1// Option A: Solid color with rounded corners2BoxDecoration(3color: Colors.blue,4borderRadius: BorderRadius.circular(16),5border: Border.all(color: Colors.grey, width: 2),6boxShadow: [7BoxShadow(8color: Colors.black26,9blurRadius: 10,10spreadRadius: 2,11offset: Offset(0, 4),12),13],14)1516// Option B: Gradient background (cannot use 'color' with gradient)17BoxDecoration(18gradient: LinearGradient(19colors: [Colors.blue, Colors.purple],20begin: Alignment.topLeft,21end: Alignment.bottomRight,22),23borderRadius: BorderRadius.circular(16),24)2526// Option C: Circular shape (cannot use 'borderRadius' with circle)27BoxDecoration(28color: Colors.blue,29shape: BoxShape.circle,30)3132// Option D: Background image33BoxDecoration(34image: DecorationImage(35image: NetworkImage('https://example.com/image.jpg'),36fit: BoxFit.cover,37),38borderRadius: BorderRadius.circular(16),39)
Do not use the `color` property of Container and the `color` inside BoxDecoration at the same time. Flutter will throw a runtime error. Use only one of them.
Instead of random values, use a small spacing scale like 4, 8, 12, 16, 24, 32.
Apply it consistently:
This makes screens look intentional and professional even with simple widgets.
The most versatile widget in Flutter. Widgets are reusable UI blocks. You combine them like LEGO pieces to build screens.
Build confidence with basics first; speed comes later.
Sketch the widget tree first, then code from top to bottom.
Most Flutter productivity comes from understanding layout rules and composing widgets cleanly.
borderRadius in BoxDecoration creates rounded corners.
horizontal affects left and right sides.
BoxShape.circle in BoxDecoration makes the container circular.
Using both color and gradient in BoxDecoration causes a runtime error. Choose one.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue