Menu
CoddyTech

Rounded Corners

Part of the Your First App section of Coddy's Flutter journey. Lesson 18 of 32.

For more than a plain color, a Container takes a decoration:. A BoxDecoration can round the corners:

Container(
  padding: EdgeInsets.all(16),
  decoration: BoxDecoration(
    color: Colors.indigo,
    borderRadius: BorderRadius.circular(12),
  ),
  child: Text('Rounded'),
)

BorderRadius.circular(12) rounds every corner with a curve 12 pixels wide.

Notice that color: moved inside the BoxDecoration. A Container cannot have both a color: and a decoration:: Flutter stops with an error, because it cannot tell which color you want.

challenge icon

Challenge

Easy

Round the corners of the pink box:

  • replace the Container's color: with a decoration:
  • make it a BoxDecoration with color: Colors.pink and borderRadius: BorderRadius.circular(16)

Try it yourself

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: Container(
            padding: EdgeInsets.all(16),
            color: Colors.pink,
            child: Text('Sale', style: TextStyle(fontSize: 32, color: Colors.white)),
          ),
        ),
      ),
    );
  }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Your First App

Practice on your own: Online Flutter compiler