Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with getx naviagtion on flutter web #3288

Open
haashtech opened this issue Jan 6, 2025 · 4 comments
Open

Issue with getx naviagtion on flutter web #3288

haashtech opened this issue Jan 6, 2025 · 4 comments
Assignees

Comments

@haashtech
Copy link

ATTENTION: DO NOT USE THIS FIELD TO ASK SUPPORT QUESTIONS. USE THE PLATFORM CHANNELS FOR THIS. THIS SPACE IS DEDICATED ONLY FOR BUGS DESCRIPTION.
Fill in the template. Issues that do not respect the model will be closed.

Describe the bug
I am using getx routing for my web project and all navigations are working file except invalid routes. i am impliment unknownroute in my getmaterialapp, but it didnt trigger if an invalid route called or even called 'not-found' route. i have reffered infinit tutorials and all of them using the same method and work well.

Reproduction code
NOTE: THIS IS MANDATORY, IF YOUR ISSUE DOES NOT CONTAIN IT, IT WILL BE CLOSED PRELIMINARY)

example:

void main() => runApp(MaterialApp(home: App()));

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      builder: (context, child) {
        ErrorWidget.builder = (FlutterErrorDetails errorDetails) {
          return CustomErrorWidget(errorDetails: errorDetails);
        };
        return child ?? const SizedBox.shrink();
      },
      title: STexts.appName,
      themeMode: ThemeMode.light,
      navigatorObservers: [RouteObserver()],
      defaultTransition: Transition.noTransition,
      theme: TAppTheme.lightTheme,
      darkTheme: TAppTheme.darkTheme,
      debugShowCheckedModeBanner: false,
      getPages: SAppRoutes.pages,
      initialRoute: SRoutes.login,
      unknownRoute: GetPage(
        name: '/not-found',
        page: () => const NotFoundPage(),
      ),
      initialBinding: GeneralBindings(),
    );
  }
}

class NotFoundPage extends StatelessWidget {
  const NotFoundPage({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(child: Text('404 - Page Not Found')),
    );
  }
}

iam attaching my routes

class SAppRoutes {
  static final List<GetPage> pages = [
    GetPage(
      name: SRoutes.n404,
      page: () => const NotFoundPage(),
    ),
    GetPage(
      name: SRoutes.login,
      page: () => const LoginScreen(),
    ),
    GetPage(
      name: SRoutes.dashboard,
      middlewares: [TRouteMiddleware()],
      page: () => const DashbordScreen(),
    ),
    GetPage(
      name: SRoutes.product,
      middlewares: [TRouteMiddleware()],
      page: () => const SSiteLayout(),
    ),],
}

also attaching route observers

class RouteObserver extends GetObserver {
  @override
  void didPush(Route? route, Route? previousRoute) {
    final sideBarController = Get.find<SidebarController>();
    if (route?.settings.name != null) {
      if (SRoutes.sideBarMenuItems.contains(route!.settings.name)) {
        sideBarController.activeItem.value = route.settings.name!;
      }
    }
  }

  @override
  void didPop(Route route, Route? previousRoute) {
    final sideBarController = Get.find<SidebarController>();

    if (previousRoute?.settings.name != null) {
      if (SRoutes.sideBarMenuItems.contains(previousRoute!.settings.name)) {
        sideBarController.activeItem.value = previousRoute.settings.name!;
      }
    }
  }
}

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'

Expected behavior
if a user change the valid url to invalid routename then the unknownRoute in GetMaterialApp is triggered and need to show the NotFoundPage() page should display.

Screenshots
Screenshot 2025-01-06 at 12 46 11 PM
Screenshot 2025-01-06 at 12 45 43 PM

Flutter Version:
sdks:
dart: ">=3.5.3 <4.0.0"
flutter: ">=3.27.0"

Getx Version:
get:
dependency: "direct main"
description:
name: get
sha256: e4e7335ede17452b391ed3b2ede016545706c01a02292a6c97619705e7d2a85e
url: "https://pub.dev"
source: hosted
version: "4.6.6"

Describe on which device you found the bug:
web

Minimal reproduce code
Provide a minimum reproduction code for the problem

@fisforfaheem
Copy link

@jonataslaw

@wanwenfeng4798
Copy link

@jonataslaw
You seem to be in a hurry. But chasing new things may not necessarily be good. Especially for production environments. The author feels like they are not a full-time developer. He is in a management position, so it is normal for him to not maintain actively. It is suggested that he can study the source code himself and implement a new one based on his ideas This can also improve one's own level;

@Aniketkhote
Copy link
Contributor

Did you try using GetX5?

@fisforfaheem
Copy link

yes getX 5 is good but not being released fully as stable ( even for testing) i think you should work on getX 2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants