Flutterando / modular

A smart project structure
https://pub.dev/packages/flutter_modular
Other
1.31k stars 254 forks source link

Modular 6.3 - flutter web - RouteNotFoundException #904

Open dtodt opened 1 year ago

dtodt commented 1 year ago

Describe the bug An app that has one screen (splash), works ok on iOS, but doesn't work on web builds, giving the exception below.

Console error ```sh Launching lib/main.dart on Chrome in debug mode... This app is linked to the debug service: ws://127.0.0.1:57368/EfjPx5Yag5E=/ws Debug service listening on ws://127.0.0.1:57368/EfjPx5Yag5E=/ws Connecting to VM Service at ws://127.0.0.1:57368/EfjPx5Yag5E=/ws Error: RouteNotFoundException: Route (//) not found dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:49 throw_ packages/result_dart/src/result.dart 291:5 getOrThrow packages/result_dart/src/async_result.dart 109:35 dart-sdk/lib/async/zone.dart 1661:54 runUnary dart-sdk/lib/async/future_impl.dart 156:18 handleValue dart-sdk/lib/async/future_impl.dart 840:44 handleValueCallback dart-sdk/lib/async/future_impl.dart 869:13 _propagateToListeners dart-sdk/lib/async/future_impl.dart 641:5 [_completeWithValue] dart-sdk/lib/async/future_impl.dart 715:7 callback dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:15 ```

Environment

flutter doctor -v ```sh [✓] Flutter (Channel stable, 3.13.6, on macOS 13.5.2 22G91 darwin-arm64 (Rosetta), locale en-BR) • Flutter version 3.13.6 on channel stable at /Users/Daniel/.puro/envs/stable/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision ead455963c (10 days ago), 2023-09-26 18:28:17 -0700 • Engine revision a794cf2681 • Dart version 3.1.3 • DevTools version 2.25.0 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /Users/Daniel/Library/Android/sdk • Platform android-33, build-tools 33.0.1 • ANDROID_HOME = /Users/Daniel/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A240d • CocoaPods version 1.13.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) [✓] VS Code (version 1.83.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.74.0 [✓] Connected device (2 available) • iPhone 15 (mobile) • 13509834-3E87-412B-9AA9-B81EB39A3DF8 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator) • Chrome (web) • chrome • web-javascript • Google Chrome 117.0.5938.149 [✓] Network resources • All expected network resources are available. • No issues found! ```
pubspec.yaml ```yml name: food description: Food publish_to: "none" version: 0.0.1+1 environment: sdk: ">=3.1.2 <4.0.0" dependencies: flutter: sdk: flutter asp: ^1.3.0 cloud_firestore: ^4.9.3 envied: ^0.3.0+3 firebase_analytics: ^10.5.1 firebase_app_check: ^0.2.0+1 firebase_app_installations: ^0.2.3+7 firebase_auth: ^4.10.1 firebase_core: ^2.17.0 firebase_crashlytics: ^3.3.7 firebase_messaging: ^14.6.9 firebase_performance: ^0.9.2+7 firebase_remote_config: ^4.2.7 firebase_storage: ^11.2.8 flutter_modular: ^6.3.2 google_fonts: ^6.1.0 google_sign_in: ^6.1.5 lottie: ^2.6.0 result_dart: ^1.1.0 sign_button: ^2.0.6 upgrader: ^8.1.0 dev_dependencies: flutter_test: sdk: flutter build_runner: ^2.4.6 envied_generator: ^0.3.0+3 flutter_lints: ^2.0.3 mocktail: ^1.0.1 mocktail_image_network: ^1.0.0 flutter: uses-material-design: true assets: - assets/animations/ ```

To Reproduce Create a new project, add modular and a page in a path different than /.

app_module.dart ```dart import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:firebase_performance/firebase_performance.dart'; import 'package:flutter_modular/flutter_modular.dart'; import 'shared/pages/splash_page.dart'; class AppModule extends Module { @override void binds(Injector i) { i.addInstance(FirebaseAnalytics.instance); i.addInstance(FirebaseAuth.instance); i.addInstance(FirebaseCrashlytics.instance); i.addInstance(FirebasePerformance.instance); } @override void routes(RouteManager r) { r.child('/splash', child: (_) => const SplashPage()); } } ```
app_widget.dart ```dart import 'package:flutter/material.dart'; import 'package:flutter_modular/flutter_modular.dart'; import 'package:google_fonts/google_fonts.dart'; class AppWidget extends StatefulWidget { const AppWidget({super.key}); @override State createState() => _AppWidgetState(); } class _AppWidgetState extends State { @override Widget build(BuildContext context) { Modular.setInitialRoute('/splash'); return MaterialApp.router( debugShowCheckedModeBanner: false, routerConfig: Modular.routerConfig, theme: ThemeData( appBarTheme: AppBarTheme( centerTitle: true, titleTextStyle: GoogleFonts.ubuntu( color: Colors.white, fontSize: 24.0, ), ), colorScheme: const ColorScheme.dark(), useMaterial3: true, ), title: '', ); } } ```

Expected behavior Should open the app and redirect to the initial route.

Obs: the app works when I don't change the initial path and provide the splash path like this: r.child('/', child: (_) => const SplashPage());

DevJHenrique commented 1 year ago

Estou passando pelo mesmo problema e já tem uma issue #900 aberta indicando o mesmo problema no Modular.setInitialRoute

Para contornar esse problema utilizei um redirect nas rotas

r.redirect('/', to: '/splash/');

Acredito que não seja uma boa pratica, mas funcionou.