Flutter Web to update address bar url when switch to BottomNavigationBar

Viewed 1081

I have used the BottomNavigationBar on flutter WEB and added view (StatelessWidget class) on BottomNavigationBarItem. When I am switching to view I need to update address URL.

For example: BottomNavigationBarItem to added below option item

  • home
  • payment
  • guide
  • setting

When I'm first launch then it will be home view then URL is http://localhost:64289/#/home When i'm switch to payment view then URL will be the same(Not updating).

But I need the URL should be like below http://localhost:64289/#/payment

I have used the GetX if anyone can give answer Getx as well then it is fine.

I have tried out the Get.toNamed('/payment'); OR Navigator.pushNamed(context, routeName) as well but in that case, I need to set and bottom bar on each page. so please help me any other way to achieve it.

2 Answers

Use

  static const MAIN_PAGE = '/main-page/:id';

In Routes and set

initialRoute: "/main-page/0"

In GetMaterialApp(main.dart) and set

var parameters = Get.parameters;
tabIndex.value = int.parse(parameters['id'].toString());

In onInit(MainPageController)

Finally add

Get.offAllNamed("/main-page/"+tabIndex.value.toString());

When change tab.

Related