How to Create a Circle Button in Flutter

If you want to create a circle button in flutter this code example below will give you a little insight on how to go about it.

The code is based on flutter version 1.0.0.

Main.dart (App entry point)

import 'package:flutter/material.dart';
import 'circular_button.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      //home: MyHomePage(title: 'Flutter Demo Home Page'),
      home: CircularButton(),
    );
  }
}


circular_button.dart

Create an instance of the class CircularButtonand assign it to the MaterialAppwidget home attribute as show above.

import 'package:flutter/material.dart';

class CircularButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Circular Button Example"),
      ),
      body: Center(
          child: GestureDetector(
        onTap: () {},
        child: ClipOval(
          child: Container(
            color: Colors.blue,
            height: 120.0, // height of the button
            width: 120.0, // width of the button
            child: Center(child: Text('A Circular Button')),
          ),
        ),
      )),
    );
  }
}

flutter circle button

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

2 Comments

  1. Avatar

Add a Comment