Skip to content

StatefulShellRouteData generated as const on extension #161305

Closed
@on3ss

Description

@on3ss

Steps to reproduce

  1. create a StatefulShellRouteData with multiple branches but single route for each branch
  2. Add a custom scaffold for nesting routes with a bottom navigation bar

Expected results

on the generated file, the extension on the class that extends StatefulShellRouteData must not be returned as const.

Actual results

on the generated file, the extension on the class that extends StatefulShellRouteData returned as const.

Code sample

Code sample
import 'package:academix/features/chat/chat.dart';
import 'package:academix/features/homework/homework.dart';
import 'package:academix/features/my_class/my_class.dart';
import 'package:academix/widgets/scaffold_with_nested_navigation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:academix/features/home/home.dart';

import '../features/assignments/assignments.dart';

part 'router.g.dart';

@TypedStatefulShellRoute<AppShellRouteData>(
  branches: [
    TypedStatefulShellBranch(
      routes: [TypedGoRoute<HomePageRoute>(path: '/')],
    ),
    TypedStatefulShellBranch(
      routes: [TypedGoRoute<MyClassPageRoute>(path: '/my-class')],
    ),
    TypedStatefulShellBranch(
      routes: [TypedGoRoute<HomeworkPageRoute>(path: '/homework')],
    ),
    TypedStatefulShellBranch(
      routes: [TypedGoRoute<AssignmentsPageRoute>(path: '/assignments')],
    ),
    TypedStatefulShellBranch(
      routes: [TypedGoRoute<ChatPageRoute>(path: '/chat')],
    ),
  ],
)
class AppShellRouteData extends StatefulShellRouteData {
  @override
  Widget builder(
    BuildContext context,
    GoRouterState state,
    StatefulNavigationShell navigationShell,
  ) =>
      ScaffoldWithNestedNavigation(navigationShell: navigationShell);
}

@immutable
class HomePageRoute extends GoRouteData {
  @override
  Widget build(BuildContext context, GoRouterState state) {
    return const MyHomePage();
  }
}

@immutable
class MyClassPageRoute extends GoRouteData {
  @override
  Widget build(BuildContext context, GoRouterState state) {
    return const MyClassPage();
  }
}

@immutable
class AssignmentsPageRoute extends GoRouteData {
  @override
  Widget build(BuildContext context, GoRouterState state) {
    return const AssignmentsPage();
  }
}

@immutable
class HomeworkPageRoute extends GoRouteData {
  @override
  Widget build(BuildContext context, GoRouterState state) {
    return const HomeworkPage();
  }
}

@immutable
class ChatPageRoute extends GoRouteData {
  @override
  Widget build(BuildContext context, GoRouterState state) {
    return const ChatPage();
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
lib/router/router.g.dart:61:13: Error: Cannot invoke a non-'const' constructor where a const expression is expected.
Try using a constructor or factory that is 'const'.
      const AppShellRouteData();

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.1, on Microsoft Windows [Version 10.0.26100.2605], locale en-IN)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✗] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✗] Visual Studio - develop Windows apps
    ✗ Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[✓] Android Studio (version 2024.2)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 3 categories.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listfound in release: 3.27Found to occur in 3.27found in release: 3.28Found to occur in 3.28has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_router_builderThe go_router_builder packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionteam-go_routerOwned by Go Router teamtriaged-go_routerTriaged by Go Router team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions