Search code examples
flutterfirebasedartbuttonboolean

How to redirect a user after a boolean check in Flutter


I have a button that checks the time difference, so I would want the user to be redirected if the button is active or when he clicks on the button when it is active. Below is what I have tried but I'm getting error, I will so much appreciate if anyone can help me out. below is what i have tried

 ElevatedButton( child: Text("Button2"), onPressed: \_isButtonActive ? \_handleButtonPress ? () { // to direct them to another page or API } : null),

Future<void> _handleButtonPress() async {
    try {
      await _firestore.collection('WithdrawalsAuthentications').doc(_uid).set({
        'date': Timestamp.now(),
      //    "uID": user.uid,
      //  "email":  user.email!,
       "amountRequested": _flexAmount,
      });
      setState(() {
        _isButtonActive = false;
      });
    } catch (e) {
      print("Error handling button press: $e");
    }
  }
    

but am gettting error "Conditions must have a static type of 'bool'. Try changing the condition." above is my handleButton method


Solution

  • _handleButtonPress not a boolean value thats why its gives error "conditions must have a static type of bool, try changing the condition" Try onPressed method like below

     onPressed: _isButtonActive ? () async {
                await _handleButtonPress();
              } : null,