Adding Rounded Containers In Flutter

In this article, you will learn How To Add Rounded Containers or Corners to Widgets In Flutter. Import Material Package We will first import the…

The post Adding Rounded Containers In Flutter appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Jatin Hemnani

In this article, you will learn How To Add Rounded Containers or Corners to Widgets In Flutter.

Import Material Package

import 'package:flutter/material.dart';

We will first import the Material Package from Flutter in order to add material design to our Flutter App.

Adding Material App To the main function

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

Here we have created the main function which is necessary in order to run our Dart code.

Creating Scaffold

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: Text('Home'),
        centerTitle: true,
      ),
      body: Home(),
    ));
  }
}

Above we have a State Less Widget which has a Scaffold widget to show our Material Design-like App Bar. And we have assigned the body to the Home() widget which we will create below.

Creating Home Widget

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ClipReact(
      borderRadius: BorderRadius.circular(40),
      child: Container(
        height: 300,
        width: 300,
        color: Colors.red,
      ),
    );
  }
}

Now we have a Home widget with two widgets nested. ClipReact() widget also acts as a Container widget if you want rounded corners for your child widget and in our case, we need our child widget to have Rounded Corners.

ClipReact has a property borderRadius to give border-radius to your child widget and it takes the BorderRadius method and in order to get rounded corners, we can do it by BorderRadius.circular(40). You can choose the amount according to your need.

Result

The post Adding Rounded Containers In Flutter appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Jatin Hemnani


Print Share Comment Cite Upload Translate Updates
APA

Jatin Hemnani | Sciencx (2021-02-24T12:52:03+00:00) Adding Rounded Containers In Flutter. Retrieved from https://www.scien.cx/2021/02/24/adding-rounded-containers-in-flutter/

MLA
" » Adding Rounded Containers In Flutter." Jatin Hemnani | Sciencx - Wednesday February 24, 2021, https://www.scien.cx/2021/02/24/adding-rounded-containers-in-flutter/
HARVARD
Jatin Hemnani | Sciencx Wednesday February 24, 2021 » Adding Rounded Containers In Flutter., viewed ,<https://www.scien.cx/2021/02/24/adding-rounded-containers-in-flutter/>
VANCOUVER
Jatin Hemnani | Sciencx - » Adding Rounded Containers In Flutter. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/24/adding-rounded-containers-in-flutter/
CHICAGO
" » Adding Rounded Containers In Flutter." Jatin Hemnani | Sciencx - Accessed . https://www.scien.cx/2021/02/24/adding-rounded-containers-in-flutter/
IEEE
" » Adding Rounded Containers In Flutter." Jatin Hemnani | Sciencx [Online]. Available: https://www.scien.cx/2021/02/24/adding-rounded-containers-in-flutter/. [Accessed: ]
rf:citation
» Adding Rounded Containers In Flutter | Jatin Hemnani | Sciencx | https://www.scien.cx/2021/02/24/adding-rounded-containers-in-flutter/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.