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
EasyRound the corners of the pink box:
- replace the
Container'scolor:with adecoration: - make it a
BoxDecorationwithcolor: Colors.pinkandborderRadius: 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)),
),
),
),
);
}
}
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