Search code examples
flutterdartbuttoncolorsstyles

How to make circle Gradient color button in Flutter | Flutter


ConstrainedBox(
                constraints: BoxConstraints.tightFor(width: 60, height: 60),
                child: ElevatedButton(
                  child: Text(
                    'GO',
                    style: TextStyle(fontSize: 18),
                  ),
                  onPressed: () {},
                  style: ElevatedButton.styleFrom(
                    shape: CircleBorder(),
                  ),
                ),
              ),

Iam trying to create a gradient circle shaped button, but in this code it creates rounded circle button but how i add gradient color to it.


Solution

  • You can use a FloatingActionButton for this:

    enter image description here

    import 'package:flutter/material.dart';
    import 'package:flutter_hooks/flutter_hooks.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          home: MyWidget(),
        );
      }
    }
    
    class MyWidget extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Center(
          child: FloatingActionButton(
            child: Container(
              width: 60,
              height: 60,
              child: Icon(Icons.add),
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                gradient: LinearGradient(
                  colors: [Color(0xff43cea2), Color(0xff185a9d)],
                ),
              ),
            ),
            onPressed: () {},
          ),
        );
      }
    }