Flutterando / auto_injector

Dependency injection system. But without build_runner :)
https://pub.dev/packages/auto_injector
Other
54 stars 15 forks source link

BUG - Support for WebAssembly (Wasm) #23

Open joaovvrodrigues opened 1 week ago

joaovvrodrigues commented 1 week ago

Describe the bug:

Flutter 3.24 or newer supports running a web app with Wasm using flutter run --wasm.

Auto-Injector for wasm.

RuntimeError: dereferencing a null pointer at ModularRouteInformationParser. This could be related to an issue when parsing routes in Flutter Web.

AutoInjector Error: There's an error in the AutoInjectorImpl._resolveBind method, specifically when resolving an instance by class name. This might indicate an issue with dependency injection where the required instance could not be found or injected. It seems that the core issue is within the dependency injection process (AutoInjectorImpl) and how ModularRouteInformationParser handles routing, especially on Flutter Web.

Captura de Tela 2024-11-14 às 12 27 06

Environment: Flutter: 3.24.4 flutter_modular: ^6.3.4 auto_injector: ^2.0.5

To Reproduce

import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(ModularApp(
    module: AppModule(),
    child: const MyApp(),
  ));
}

class AppModule extends Module {
  @override
  void routes(RouteManager r) {
    r.child("/",
        child: (context) => const MyHomePage(title: 'Flutter Demo Home Page'));
  }
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      routerConfig: Modular.routerConfig,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
joaovvrodrigues commented 1 week ago

Reported by @ArturLevchuk a more 2 weeks ago.