flutterflutter-webflutter-go-router

Flutter Go Router no back button and nothing to pop


I am using Go Router on my flutter project and I noticed that the back button is not presented anymore. Even when I specifically add it I get the following error:

======== Exception caught by gesture =============================================================== The following GoError was thrown while handling a gesture: There is nothing to pop When the exception was thrown, this was the stack: #0 GoRouterDelegate.pop (package:go_router/src/delegate.dart:120:5) #1 GoRouter.pop (package:go_router/src/router.dart:284:21) #2 RecordDetailState.build. (package:random_me/screens/record/detail.dart:70:36) #3 _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1072:21) #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:253:24) #5 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:627:11) #6 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:306:5) #7 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:239:7)

  Widget build(BuildContext context) {
    AppTranslations.init(context);
    return Scaffold(
      appBar: AppBar(
          title: Text(TRANSLATION.record_detail),
          leading: IconButton(
            onPressed: () {
              GoRouter.of(context).pop();
            },
            icon: Icon(Icons.arrow_back_ios),
            //replace with our own icon data.
          )),

Edit: If I call

GoRouter.of(context).push(CategoryDetail.routeName); 

instead of

GoRouter.of(context).go(CategoryDetail.routeName);

it works;


Solution

  • Fixed: If I call

    GoRouter.of(context).push(CategoryDetail.routeName); 
    

    instead of

    GoRouter.of(context).go(CategoryDetail.routeName);
    

    it works;