DEV Community

Discussion on: Flutter Web - Fix Refresh & Back button Problem

Collapse
 
korca0220 profile image
ParkJuneWoo

Hello!! This article was really helpful! Thank you
But how did you handle it like Get.back()? An error occurs in this process. Same as Get.rootDelegate.popRoute().

I would ultimately like to implement the following elements.

  1. Go back, go forward after refresh in a web browser. -> Success
  2. Widgets that return to the previous page when the <- button is pressed (previously use Get.back())
Collapse
 
kkimj profile image
Jiun Kim • Edited

Hello!
We can go back via html API, dart:html

// import
import 'dart:html' as html;

{
  // within callBack
  // ..
  html.window.history.back();
}
Enter fullscreen mode Exit fullscreen mode

Thanks!
HANW!

Collapse
 
kkimj profile image
Jiun Kim

Helloo Buddies~

Collapse
 
swimmingkiim profile image
swimmingkiim

You can do that by using Get.roodDelegate.popHistory with custom logic.

  1. First, override popHistory method in AppRouterDelegate
class AppRouterDelegate extends GetDelegate {
  GetNavConfig get prevRoute =>  // here
      history.length < 2 ? history.last : history[history.length - 2];

  @override
  Future<GetNavConfig> popHistory() async {  // and here
    final result = prevRoute;
    Get.rootDelegate.offNamed(prevRoute.currentPage!.name);
    return result;
  }

  @override
  Widget build(BuildContext context) {
    return Navigator(
      ......
    );
  }
}
Enter fullscreen mode Exit fullscreen mode
  1. And call it like this
Get.rootDelegate.popHistory();
Enter fullscreen mode Exit fullscreen mode

I've tested it and it works for me. Hope this can help you :-)

Collapse
 
korca0220 profile image
ParkJuneWoo

Thank you!! That was really helpful

If you refresh it, it doesn't work popHistory, but I think we can solve it in a different way!

Thread Thread
 
shambhulky profile image
shambhulky • Edited

How you have implemented this? Even without overriding, getting same result.