Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

dart flutter : No named parameter with the name 'primary'

I have this block of code

              TextButton(
                onPressed: () {},
                child: Text('Forgot your password?'),
                style: TextButton.styleFrom(
                  primary: Theme.of(context).colorScheme.primary,
                ),
              ),

Yet I get the error below as I run the flutter code:

../../../flutter/packages/flutter/lib/src/material/text_button.dart:146:22: Context: Found this candidate, but the arguments don't match.
  static ButtonStyle styleFrom({
                     ^^^^^^^^^
lib/main.dart:93:19: Error: No named parameter with the name 'primary'.
                  primary: Theme.of(context).colorScheme.primary,
                  ^^^^^^^

Do I need to check my gradle version or whatever? I am very new to flutter any help is appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The error you are seeing is because the styleFrom method does not have a primary parameter anymore. As can be seen in the documentation, the constructor for this method has Color arguments for different color attributes.

ButtonStyle styleFrom(
{Color? foregroundColor,
Color? backgroundColor,
Color? disabledForegroundColor,
Color? disabledBackgroundColor,
Color? shadowColor,
Color? surfaceTintColor,
Color? iconColor,
Color? disabledIconColor,
double? elevation,
TextStyle? textStyle,
EdgeInsetsGeometry? padding,
Size? minimumSize,
Size? fixedSize,
Size? maximumSize,
BorderSide? side,
OutlinedBorder? shape,
MouseCursor? enabledMouseCursor,
MouseCursor? disabledMouseCursor,
VisualDensity? visualDensity,
MaterialTapTargetSize? tapTargetSize,
Duration? animationDuration,
bool? enableFeedback,
AlignmentGeometry? alignment,
InteractiveInkFeatureFactory? splashFactory}
)

So, if you want to set the background color, then you need to do the following:

TextButton(
                onPressed: () {},
                child: Text('Forgot your password?'),
                style: TextButton.styleFrom(
                  backgroundColor: Theme.of(context).colorScheme.primary,
                ),
              ),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading