jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.24k stars 1.61k forks source link

Web application crashes when using url_strategy #1165

Open melwinlobo18 opened 3 years ago

melwinlobo18 commented 3 years ago

Describe the bug I'm using url_strategy package which is used to remove the "#" in the URL. I get the following error when try to access the non-existent path.

A GlobalKey was used multiple times inside one widget's child list.

**Reproduction code

example:

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_strategy/url_strategy.dart';

void main() {
  setPathUrlStrategy();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      initialRoute: '/',
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      getPages: [
        GetPage(
          name: '/',
          page: () => FirstPage(),
        ),
      ],
    );
  }
}

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("First Page"),
      ),
    );
  }
}

Expected behavior No error is thrown when url_strategy is not used.

Getx Version: get: ^3.26.0

Describe on which device you found the bug: Chrome

hiuryanderson commented 3 years ago

Try changing the file below.

Locate the file: web> index.html

Inside the tag place: < base href = "/" >

In my project it works well.

melwinlobo18 commented 3 years ago

I have changed it. It works fine with the existing routes but when I try with http://localhost:8000/non-existent-path it throws the error.

hiuryanderson commented 3 years ago

Try add the unknownRoute in GetMaterialApp file below.

Locate the file: lib> main.dart

add in GetMaterialApp( .. unknownRoute: GetPage( name: '/404-not-found', page: () => NotFoundPage(), ), ....

In my project it works well.

iMrLopez commented 3 years ago

This also happens if you try to reproduce issue #1170 after installing the url_strategy package

iMrLopez commented 3 years ago

@melwinlobo18 try again with the latest version from the repo, we just landed #1171 and it is working for me