Was enabled flag for ElevatedButton removed in an update?

Viewed 59

I'm trying to use a bloc to check valid input and make an ElevatedButton(the new implementation for RaisedButton) either enabled or disabled. However, the enabled flag seems to not be implemented in the ElevatedButton source code despite it being shown in the docs as a constructor parameter. Was this changed and the docs not updated? I'm on flutter 1.22.4.

For context, I am using a global ElevatedButton widget for my app. Passing a null function to it caused it to cause an error. So I need the enabled flag to manually set the button enabled or not.

/// Get a custom raised button
Widget getRaisedButton(
    {String buttonText,
    dynamic icon,
    Color buttonColor,
    Color textColor,
    dynamic colors,
    Function onPressed,
    EdgeInsetsGeometry padding,

    /// A widget to be displayed instead of the button text
    Widget buttonWidget,
    ButtonStyle buttonStyle}) {
  return ElevatedButton(
    onPressed: onPressed(),
    style: ButtonStyle(
            visualDensity: VisualDensity.adaptivePlatformDensity,
            backgroundColor: MaterialStateProperty.all<Color>(buttonColor),
            padding: MaterialStateProperty.all<EdgeInsetsGeometry>(padding))
        .merge(buttonStyle),
    child: icon != null
        ? Row(
            // mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Padding(padding: EdgeInsets.only(left: 8)),
              icon,
              Spacer(),
              Text(
                buttonText,
                style: defaultTextStyle(
                    textColor != null ? textColor : colors.mainTextColor),
              ),
              Spacer()
            ],
          )
        : buttonWidget != null
            ? buttonWidget
            : Text(buttonText,
                style: defaultTextStyle(
                    textColor != null ? textColor : colors.mainTextColor)),
  );
}

Attempt to pass null

StreamBuilder<bool>(
        stream: bloc.inputValid,
        builder: (context, snapshot) {
          return getRaisedButton(
              colors: colors,
              buttonText: continueText,
              buttonColor: colors.mainButtonsColor,
              textColor: colors.mainBackgroundColor,
              buttonWidget: authenticationState.isAuthenticating
                  ? CircularProgressIndicator(
                      backgroundColor: colors.mainBackgroundColor,
                    )
                  : null,
              padding: EdgeInsets.symmetric(vertical: 12, horizontal: 100),
              onPressed: !snapshot.hasData
                  ? null
                  : () async {
                      final form = _formKey.currentState;

                      if (form.validate()) {
                        form.save();
                        //TODO: Use dependency injection for these
                        DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
                        AndroidDeviceInfo androidInfo =
                            await deviceInfo.androidInfo;

                        if (androidInfo.isPhysicalDevice) {
                          context
                              .read(authenticationProvider)
                              .setFullPhoneNumber(
                                  "${authenticationState.phoneNumberPrefix}${_user.phoneNumber}");
                          context
                              .read(authenticationProvider)
                              .verifyPhoneNumber(context,
                                  "${authenticationState.phoneNumberPrefix}${_user.phoneNumber}");
                        } else {
                          Navigator.of(context).push(MaterialPageRoute(
                              builder: (context) => OtpPage()));
                        }
                      }
                    });
        }),
1 Answers

Noticed the elevated flag is read-only. I will pass null to the function anyway, if it causes an app breaking error I will have to use a separate Elevated button here instead of the global one then pass null to the onPressed function.

Related