0

I'm making an edit profile page in my flutter app using laravel as my database. I got an error saying that my boolean expression must not be null. How would I be able to solve this?

void _update()async {

setState(() {
  _isLoading = true;
});
var userData;

var update = await Network().editData(userData, '/user Data');
var body = json.decode(update.body);
if(body['Done']){
  SharedPreferences localStorage = await SharedPreferences.getInstance();
  localStorage.setString('user Data', json.encode(body['user Data']));



  Navigator.push(
    context,
    new MaterialPageRoute(
        builder: (context) => Profile()
    ),
  );
}

setState(() {
  _isLoading = false;
});

} }

Here is the stacktrace:

E/flutter (28905): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)]
Unhandled Exception: Failed assertion: boolean expression must not be null
E/flutter (28905): #0 _EditState._update (package:project1app/screen/editprofile.dart:264:12)
CoderUni
  • 5,474
  • 7
  • 26
  • 58
Sameer Pradhan
  • 25
  • 1
  • 10
  • Your userData variable is null. Set a value to it before this line of code: var update = await Network().editData(userData, '/user Data'); . Don't just copy pasting code and learn programming first. It will help you fix simple problems easily. – CoderUni Mar 25 '20 at 09:07
  • Does this answer your question? [How do I solve the 'Failed assertion: boolean expression must not be null' exception in Flutter](https://stackoverflow.com/questions/51052399/how-do-i-solve-the-failed-assertion-boolean-expression-must-not-be-null-excep) – Abhinav Suman Mar 25 '20 at 10:59

1 Answers1

1

This problem occurs when one of your defined boolean type variable is not initialized with default value, for example maybe you have you bool _isLoading; is not defined as should bool _isLoading = false; or bool _isLoading = true;

Ampersanda
  • 2,016
  • 3
  • 21
  • 36
  • Hi i know its already right but can you like tell us what to do so we can solve it. he almost has the same code as mine so please help me. –  Aug 03 '20 at 08:23
  • 1
    @xAtifx you need to initialize `_isLoading` value either set it to `true` or `false` – Ampersanda Aug 03 '20 at 12:03