Ashfaq
Ashfaq

Reputation: 435

Flutter Web - How to reload currently Active Page

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?

Upvotes: 31

Views: 37568

Answers (4)

eko
eko

Reputation: 662

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();

Upvotes: 7

MickaelHrndz
MickaelHrndz

Reputation: 3832

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.

Upvotes: 9

Technical Radar
Technical Radar

Reputation: 111

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.

Upvotes: 2

Shekar Mudaliyar
Shekar Mudaliyar

Reputation: 486

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

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

Upvotes: 28

Related Questions