Home > Mobile >  Error: Method 'toUpperCase' cannot be called on 'String?' because it is potentia
Error: Method 'toUpperCase' cannot be called on 'String?' because it is potentia

Time:11-12

what should i repair? it's error.

characterList[index]['real_name'].toUpperCase()

How can fix the error?

CodePudding user response:

Add null check like this

characterList[index]['real_name']!.toUpperCase()

or change String? to String

CodePudding user response:

if you're sure that it can't be null but just have a nullable ?, just cast it like this:

(characterList[index]['real_name'] as String).toUpperCase()
  •  Tags:  
  • dart
  • Related