Неисправность свойства onPressed Flutter - PullRequest
0 голосов
/ 10 марта 2020
  • Я создал расширенный класс из RaisedButton. При передаче параметра onPressed класс отклоняет сообщение о том, что накопитель нулевой.

  • Класс

class VecRaisedButton extends RaisedButton {
  VecRaisedButton({
    text,
    elevation,
    onPressed,
    colorButton = CorPrimaria,
    colorFont,
    splashColor: CorBranca
  }) :
    super(
      child:VecText(text: text, textAlign: TextAlign.center, color: colorFont),
      shape:RoundedRectangleBorder( borderRadius: BordaArredondadaApenas4(10, 10, 10, 10)),
      splashColor:splashColor,
      elevation:elevation,
      onPressed: () => onPressed,
      color:colorButton,
    );
}
  • Вызов класса
child: VecRaisedButton(
   text: "Enviar",
   colorFont: CorBranca,
   onPressed: Navigator.push(context, MaterialPageRoute(builder: (context) => Layout_Menu())),
)

Кто-нибудь может мне помочь?

1 Ответ

2 голосов
/ 10 марта 2020

Изменить:

  elevation:elevation,
  onPressed: () => onPressed,

на:

  elevation: elevation,
  onPressed: onPressed, // just pass along the Function

, а это:

   colorFont: CorBranca,
   onPressed: Navigator.push(context, 

на это:

   colorFont: CorBranca,
   onPressed: () => Navigator.push(context, // onPressed takes a Function

Однако, как правило, вы должны создавать новые виджеты, а не расширять их. Это означает создание класса, расширяющего StatelessWidget, а затем возврат правильной стилизованной поднятой кнопки в build.

вашего нового виджета.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...