让自定义的RisedButton展开

问题描述 投票:0回答:1

我是新来的翩翩起舞和建立自定义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)),
      ),
    );
  }
}

但我在使用它与扩展的小部件时,我得到了这样的结果。

enter image description here

如何使其100%的父宽展开?

用double.infinity

enter image description here

有集装箱

enter image description here

flutter button width
1个回答
1
投票

把RaisedButton包在ButtonTheme里面,并指定minWidth。

ButtonTheme(
 minWidth: double.infinty, //takes up all the width 
 child: RaisedButton(), 
) 
© www.soinside.com 2019 - 2024. All rights reserved.