Сделать настраиваемую кнопку RisedButton раскрыть - PullRequest
0 голосов
/ 06 мая 2020

Я новичок в флаттере и создании пользовательского 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

1 Ответ

1 голос
/ 06 мая 2020

Оберните RaisedButton внутри ButtonTheme и укажите minWidth.

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