-1

Error:

'Null' is not a subtype of type 'String'
if (loginProvider.errorMessage != true)
  Container(
    color: Colors.amberAccent,
    child: ListTile(
      title: Text(loginProvider.errorMessage), 
      leading: Icon(Icons.error), 
      trailing: IconButton(
      icon: Icon(Icons.close),
      onPressed: (){},
    ),
  ),
)
Valentin Vignal
  • 6,151
  • 2
  • 33
  • 73
noob
  • 1
  • 2

3 Answers3

0

if (loginProvider.errorMessage != true) then it means that loginProvider.errorMessage is empty so it is null and there was no errorMessages and it has no vaule. then when you want to show it in the text widget it throws this error. because it's like writing this: Text(null). which is wrong because you have to provide a string for Text widget.

Benyamin
  • 1,008
  • 11
  • 18
  • hey Benyamin thnks for quick answer. can u please give me an example how should i provide String for Text widget i. I tried many ways really i did't get it. each time it throw same error – noob Aug 14 '21 at 10:54
  • what u are trying to provide for Text widget should be a string. for example try this: Text('This should be a string value') – Benyamin Aug 14 '21 at 13:40
0

Replace

title: Text(loginProvider.errorMessage), 

with

title: Text(loginProvider?.errorMessage ?? 'Error') 
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
0

I believe you need to change your if statement to

if (loginProvider.errorMessage != null)
Valentin Vignal
  • 6,151
  • 2
  • 33
  • 73