Condition must have static type of bool

11,774

Use in initState() like

 bool alreadySaved = false;

  @override
  void initState() {
    super.initState();
    String pair = "pair_value";
    DBHelper.getAllEmployees().then((value) {
      setState(() {
        alreadySaved = value.contains(pair);
      });
    });
  }
Share:
11,774
Adrita Rahman
Author by

Adrita Rahman

Updated on June 30, 2022

Comments

  • Adrita Rahman
    Adrita Rahman almost 2 years

    I am not able to use future bool here.. is there any way i can use future bool in this type of conditions.. or is there any better way to do this?

     Widget _buildRow(String pair) {
    
    
        final Future<bool> alreadySaved = DBHelper.getAllEmployees().then((value) => value.contains(pair));
        print("Already saved $alreadySaved");
        print(pair);
        return FutureBuilder(
          future: DBHelper.getAllEmployees(),
          builder: (context, AsyncSnapshot<List<FavrtTableModel>> snapshot) =>
          snapshot.connectionState == ConnectionState.waiting ? Center(
            child: Icon(Icons.more_horiz),
          ):IconButton(
            icon: new  Icon(
              alreadySaved ? Icons.favorite : Icons.favorite_border,
              color:alreadySaved? Colors.red : Colors.white,
            ),onPressed: (){
            setState(() {
              if (alreadySaved) {
                _saved.remove(pair);
                _deleteEmployee(pair);
              } else {
                _saved.add(pair);
                _insert(pair);
    
    
              }
            });
          },
          ),
        );
      }
    
  • Adrita Rahman
    Adrita Rahman over 3 years
    i thought of that.. but the problem is in the pair value.. it cannot be shifted to initstate(),.. actually the pair value comes from a future builder in another widget,.
  • Jitesh Mohite
    Jitesh Mohite over 3 years
    That's ok but you can move this logic to another widget class? and pass pair value to that widget. or maybe you can create stateful widget for that and use initState() like my answer
  • Adrita Rahman
    Adrita Rahman over 3 years
    sorry.. i forgot..Thank you!
  • funder7
    funder7 over 3 years
    I was thinking about all except this...thanks!