flutter - How to make a raised button that has a gradient background?

后端 未结 10 1922
野性不改
野性不改 2021-01-31 14:52

Is there a way to change the raised button background color to a gradient? if not, how can I achieve something like this?

10条回答
  •  眼角桃花
    2021-01-31 15:56

    Flutter RaisedButton Tutorial

    import 'package:flutter/material.dart';
    void main() {
    runApp(MyApp());
    }
    class MyApp extends StatelessWidget {
     @override
     Widget build(BuildContext context) {
     
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Gradient RaisedButton Example'),
        ),
        body: Center(
          child: RaisedButton(
            textColor: Colors.white,
            padding: EdgeInsets.all(0.0),
            shape: StadiumBorder(),
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(25.0),
                gradient: LinearGradient(
                  colors: [
                    Color(0xFF00b09b),
                    Color(0xFF96c93d),
                  ],
                ),
              ),
              child: Text(
                'ANDROIDRIDE',
                style: TextStyle(fontSize: 15.0),
              ),
              padding: EdgeInsets.symmetric(horizontal: 70.0, vertical: 15.0),
            ),
            onPressed: () {
              print('Gradient RaisedButton clicked');
            },
          ),
        ),
      ),
    );
      }
    }
    

提交回复
热议问题