简体   繁体   中英

How do I create a Flatbutton in flutter with 2 color? not gradient, 2 solid color side by side

How do I create a Flatbutton in flutter with 2 colors? not gradient, 2 solid color side by side. 在此处输入图片说明

might be a shorter answer using gradient and stops

          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors:  [Colors.red, Theme.of(context).buttonColor] 
              stops: [0.5, 0.5]
            ),
            borderRadius: BorderRadius.circular(10.0),
          ),

Try this code. You can tweak it to meet your needs

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FlatButton(
      onPressed: () {},
      child: Container(
        height: 50,
        width: 100,
        child: Stack(
          children: [
            Row(
              children: [
                Expanded(child: Container(color: Colors.red)),
                Expanded(child: Container(color: Colors.blue)),
              ],
            ),
            Center(child: Text('PRESS ME')),
          ],
        ),
      ),
    );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM