26

I am using Flutter for developing a website. Everything is working fine with Flutter except when it comes to reloading the page. When I press the refresh button in the browser, the whole web app gets reloaded.

For example, if I have navigated to four pages from the initial page, when I press the refresh button from the fourth page, the initial page gets loaded and I'll have to manually browse all the way to the fourth page again.

Is there any way to load the currently active page in Flutter?

Ashfaq
  • 385
  • 1
  • 3
  • 10

4 Answers4

25

Or you can just use this as it refreshes the whole window natively

import 'dart:html' as html;
html.window.location.reload();
8

Check out navigation with named routes as it maps URLs seamlessly when using Flutter Web.

EDIT : If you want URL parameters (like an id, a token...), check out this article.

MickaelHrndz
  • 3,604
  • 1
  • 13
  • 23
4
import 'dart:html' as html;
html.window.location.reload();

as this is not allowed according to https://dart-lang.github.io/linter/lints/avoid_web_libraries_in_flutter.html

this is how i have resolved my issue:

import this package

https://pub.dev/packages/universal_html/install

import whereever you want to use

import 'package:universal_html/html.dart' as html;

and you can use it like this

html.window.location.reload();
eko
  • 532
  • 1
  • 5
  • 12
1

Use Navigator to push to the same page. .ie. If CurrentPage() is your page that needs to be refreshed then use:

Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => CurrentPage()));

This will reload the page.