skip to Main Content

How to create button using stack widgets and curved desgin with out background images

How to create button using stack widgets and curved desgin with out background images.

2

Answers


  1. hope it helps 🙂

    enter image description here

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(
        const MaterialApp(
          home: MyApp(),
        ),
      );
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Container(
              width: 200,
              height: 50,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20),
                image: const DecorationImage(
                  image: AssetImage(
                    'assets/images/button_background.png',
                  ),
                  fit: BoxFit.cover,
                ),
              ),
              child: RawMaterialButton(
                shape: const RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(
                    Radius.circular(20),
                  ),
                ),
                splashColor: Colors.green,
                onPressed: () {
                  print('Hello World');
                },
                child: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 20),
                  alignment: Alignment.centerLeft,
                  child: const Text('Login', style: TextStyle(color: Colors.white)),
                ),
              ),
            ),
          ),
        );
      }
    }
    
    
    Login or Signup to reply.
  2. I would suggest using background images because it’s simpler, but if you really insist on not using them, here is an example of how to do it without background image:

    class Sample extends StatelessWidget {
      const Sample({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: ClipRRect(
              borderRadius: const BorderRadius.all(Radius.circular(20)),
              child: Container(
                height: 60,
                width: 250,
                decoration: const BoxDecoration(
                  gradient: LinearGradient(
                    colors: [Colors.green, Colors.yellow],
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                  ),
                ),
                child: RawMaterialButton(
                  onPressed: () {},
                  splashColor: Colors.green,
                  child: Stack(
                    children: [
                      Container(
                        alignment: Alignment.centerLeft,
                        padding: const EdgeInsets.only(left: 20),
                        child: const Text(
                          'Login',
                          style: TextStyle(color: Colors.white, fontSize: 18),
                        ),
                      ),
                      Positioned(
                        right: 5,
                        top: -80,
                        height: 100,
                        width: 100,
                        child: Container(
                          decoration: const ShapeDecoration(
                            color: Colors.green,
                            shape: CircleBorder(),
                          ),
                        ),
                      ),
                      Positioned(
                        right: -40,
                        top: -65,
                        height: 100,
                        width: 100,
                        child: Container(
                          decoration: ShapeDecoration(
                            color: Colors.brown.withOpacity(.9),
                            shape: const CircleBorder(),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      }
    }
    

    enter image description here

    P.S. feel free to adjust the colors and height/width values to your needs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search