HelloCW
HelloCW

Reputation: 2255

Why do I get the warning information "Modifier parameter should be named modifier" in Jetpack Compose?

I use Jetpack Compose in a Android Studio project, the code A can work well, but I get the following warning information, why ?

"Modifier parameter should be named modifier"

Code A

@Composable
fun ScreenAbout(
    rootModifier: Modifier = Modifier,
    onBack: () -> Unit,
    scaffoldState: ScaffoldState = rememberScaffoldState()
) {
    Scaffold(
        modifier = rootModifier.fillMaxSize(),
        scaffoldState = scaffoldState,
        topBar = { AboutAppBar(onBack = onBack) }
    ) { paddingValues ->

        Column(

   ...
}

Upvotes: 3

Views: 2637

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363737

There is the code to Lint Check.

It checks Composable functions with Modifiers parameters for consistency with guidelines.

For functions with one / more modifier parameters, the first modifier parameter must:

  • Be named modifier
  • Have a type of Modifier
  • Either have no default value, or have a default value of Modifier
  • If optional, be the first optional parameter in the parameter list

In you case just use:

@Composable
fun ScreenAbout(
    modifier: Modifier = Modifier,

Or if you want to suppress the warning add

@SuppressLint("ModifierParameter")
@Composable
fun ScreenAbout(
    rootModifier: Modifier = Modifier,

Upvotes: 3

Related Questions