skip to Main Content

page route was working when I last wrote the code but that suddenly changed and I don’t know why that would happen.
here is the page route code:

void pinPage(LatLng point) {
    Navigator.push(
    context,
    MaterialPageRoute(
        builder: (context) => pin_attributes(
              key: const ValueKey(1),
              local: point,
              userId: userId,
            )));
print("ran");
}

ran prints in the console, so it goes past the page route without actually routing the page

2

Answers


  1. Chosen as BEST ANSWER

    My mistake, the function was called then I tried Navigator.pop(context); to close the show dialog, and this caused it not to run properly. It worked after I modified it to first pop and then run the function.


  2. Try changing code this way,

    void pinPage(BuildContext context, LatLng point) {
      Navigator.of(context).push(
        MaterialPageRoute(
          builder: (context) => pin_attributes(
            key: const ValueKey(1),
            local: point,
            userId: userId,
          ),
        ),
      );
      print("ran");
    }
    

    You can call pinPage() function from a widget,

    GestureDetector(
      onTap: () => pinPage(context, LatLng(37.7749, -122.4194)),
      child: Text('Pin a location'),
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search