Home > database >  The named parameter ' ' isnt defined
The named parameter ' ' isnt defined

Time:11-01

I'm getting errors in my flutter app after an upgrade to flutter 3.3.6. The named parameters which throws errors as 'aren't defined' : elevation, color, shape

The snippet where i get the errors is listed below :

return ButtonTheme(
  minWidth: 110,
  child: RaisedButton(
      elevation: 0,
      child: isLoading
          ? _buildLoadingIndicatorWithColor(textColor)
          : Text(
              text,
              style: TextStyle(
                  color: textColor,
                  fontWeight: FontWeight.bold,
                  fontSize: 16),
            ),
      color: communityColor,
      onPressed: onPressed,
      shape: new RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(borderRadius))),
);

}

Here is another snippet where a similar error appears and the textColor parameter throws the same error :

return ButtonTheme(
  minWidth: minWidth,
  height: height,
  child: FlatButton(
    textColor: Colors.black87,
    child: this.child,
    onPressed: this.onPressed,
  ),
);

Here is the one related to materialTapTargetSize:

hasText
                ? TextButton(
                    style: TextButton.styleFrom(
                        materialTapTargetSize:
                            MaterialTapTargetSize.shrinkWrap),
                    onPressed: _cancelSearch,
                    child: OBText(localizationService.user_search__cancel),
                  )
                : const SizedBox(
                    width: 15.0,
                  )

As per the following documentation I read https://docs.flutter.dev/release/breaking-changes/buttons, there are changes that are needed to make it work. Help appreciated as I'm very new to flutter and a beginner to programming

CodePudding user response:

RaisedButton is deprecated. You can use ElevatedButton(). Please check below code.

ButtonTheme(
      minWidth: 110,
      child: ElevatedButton(
        style: ElevatedButton.styleFrom(
          elevation: 0,
          backgroundColor: communityColor,
          shape: new RoundedRectangleBorder(),
        ),
        child: isLoading
            ? _buildLoadingIndicatorWithColor(textColor)
            : Text(
                text,
                style: TextStyle(color: textColor, fontWeight: FontWeight.bold, fontSize: 16),
              ),
        onPressed: onPressed,
      ),
    );

For FlatButton()

ButtonTheme(
      minWidth: minWidth,
      height: height,
      child: TextButton(
        style: TextButton.styleFrom(
          foregroundColor: Colors.black87,
          tapTargetSize: MaterialTapTargetSize.shrinkWrap,
        ),
        child: this.child,
        onPressed: this.onPressed,
      ),
    );

CodePudding user response:

As K K Muhammed Fazil said change the RaisedButton to ElevatedButton

If that didn't work with you Try execute those below commands in the terminal:

First do This command

 flutter clean

And then this

 flutter pub get
  • Related