首页 > 解决方案 > 使自定义 RisedButton 展开

问题描述

我是新来的颤振和构建自定义 RisedButton 我有这个按钮

import 'package:flutter/material.dart';

class EasyButton extends StatelessWidget {
  final onPressed;
  final text;
  EasyButton(this.onPressed, this.text);
  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      onPressed: this.onPressed,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(60),
      ),
      padding: EdgeInsets.all(0),
      elevation: 2,
      splashColor: Colors.blue[300],
      child: Ink(
        decoration: new BoxDecoration(
          borderRadius: BorderRadius.circular(60),
          gradient: new LinearGradient(
            colors: [Colors.blue, Colors.blue[800]],
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
          ),
        ),
        padding: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
        child: new Text(this.text, style: TextStyle(color: Colors.white)),
      ),
    );
  }
}

但是当我将它与扩展小部件一起使用时,我得到了这个结果

在此处输入图像描述

如何使其 100% 扩展父宽度?

与双无限

在此处输入图像描述

带容器

在此处输入图像描述

标签: flutterbuttonwidth

解决方案


将 RaisedButton 包裹在 ButtonTheme 中并指定 minWidth。

ButtonTheme(
 minWidth: double.infinty, //takes up all the width 
 child: RaisedButton(), 
) 

推荐阅读