0

I have created a floatactionbutton function to build a new floating action button based on the sign in type ie. "google", "facebook", etc...

I want to capitalize the fist letter inside my build function like below but getting an error, how can I do this?

FloatingActionButton BuildLoginButton(String signInType) {
  return FloatingActionButton.extended(
    onPressed: () {},
    icon: Image.asset('assets/images/$signInType+_logo.png', height: 32, width: 32),
    signInType[0].toUpperCase(), // This Line is giving me the error
    label: Text('Sign in with Google'),
    backgroundColor: WHITE_COLOR,
    foregroundColor: DARK_COLOR,
  );
}
Samir112
  • 125
  • 1
  • 12
  • You are not executing this code inside your `onPressed` – puelo Jul 23 '22 at 14:30
  • Thank you I have corrected the posting information, but I still have the error – Samir112 Jul 23 '22 at 14:31
  • You are executing this code inside the parameter list of the constructor of `FloatingActionButton.extended` (https://api.flutter.dev/flutter/material/FloatingActionButton/FloatingActionButton.extended.html). As for capitalizing the first letter of a String there are many other threads showing that (e.g.: https://stackoverflow.com/questions/29628989/how-to-capitalize-the-first-letter-of-a-string-in-dart?rq=1) – puelo Jul 23 '22 at 14:34
  • I am getting this error when I try to capitalize: Too many positional arguments: 0 expected, but 1 found. Try removing the extra positional arguments, or specifying the name for named arguments. – Samir112 Jul 23 '22 at 14:40

1 Answers1

0

This only return the single char,

signInType[0].toUpperCase()

You can do it like

signInType = signInType[0].toUpperCase() + signInType.substring(1);
 print(signInType);

On to change it, you need to put inside onpressed or before the return .

  FloatingActionButton BuildLoginButton(String signInType) {
   // here if you like to build widget with it
   String local = signInType[0].toUpperCase() + signInType.substring(1);
    return FloatingActionButton.extended(
      onPressed: () {
      /// to change on pressed
      },
      icon: Image.asset('assets/images/$signInType+_logo.png',
          height: 32, width: 32),
      label: Text(local ),
    );
  }
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56