Search code examples
flutterwidgetcontainersflutter-animation

Custom Button using Stack


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.


Solution

  • 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)),
                ),
              ),
            ),
          ),
        );
      }
    }