Home > Software engineering >  FLUTTER button onpressed navigator push got errors
FLUTTER button onpressed navigator push got errors

Time:06-09

I've made a button to send data to firebase. I want when the button is pressed, the button is not only to send data to firebase, but I want the button makes users can go back to the homepage.

I used setData for sending the data, and I used Navigator.push, but the navigator push is errors.

final sdButton = Material( 
  elevation: 5,
  borderRadius: BorderRadius.circular(5),  
  color: const Color(0xFFD3DEDC),  
  child: MaterialButton(   
    padding: const EdgeInsets.fromLTRB(20,15,20,15),
    minWidth: MediaQuery.of(context).size.width, 
    onPressed: setData {
      Navigator.push(context, 
      MaterialPageRoute(   
        builder:(context) => Homepage(),));
  
    },

and this is the code for setData

  setData(){
    dref.child(user!.uid).set({
      'user_id' : user!.uid,
      'intime' : '15.17'
    }
    );
  }
  

CodePudding user response:

 onPressed: () {
      setData();
      Navigator.push(context, MaterialPageRoute(   
        builder:(context) => Homepage(),));
    },

CodePudding user response:

Please update onPress method to like as below.

 onPressed: (){
          setData();
          Navigator.push(context, 
          MaterialPageRoute(   
            builder:(context) => Homepage(),));
    },
  • Related