1

I've just started with Flutter and I've been looking for this problem and I didn't find anything.
I ran the command slidy start in order to create my project structure.But right now, I am getting this error import Router conflict in the App Module:

The name 'Router' is defined in the libraries 'package:flutter/src/widgets/router.dart' and 'package:flutter_modular/src/routers/router.dart (via package:flutter_modular/flutter_modular.dart)'.\nTry using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports."

This is my class right now:

import 'app_controller.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:flutter/material.dart';
import 'package:slidy_aula2_v1/app/app_widget.dart';
import 'package:slidy_aula2_v1/app/modules/home/home_module.dart';

class AppModule extends MainModule {
  @override
  List<Bind> get binds => [
        Bind((i) => AppController()),
      ];

  @override
  List<Router> get routers => [
        Router(Modular.initialRoute, module: HomeModule()),
      ];

  @override
  Widget get bootstrap => AppWidget();

  static Inject get to => Inject<AppModule>.of();
}

Do you all know how to fix it?

John Joe
  • 12,412
  • 16
  • 70
  • 135
user6076
  • 15
  • 5

1 Answers1

1

You have two Router class in

package:flutter/src/widgets/router.dart

and

package:flutter_modular/src/routers/router.dart

Define a prefix to the flutter_modular package:

import 'package:flutter_modular/flutter_modular.dart' as ModularRouter; 

if you are using the Router class in flutter_modular, change Router to ModularRouter.Router.

class AppModule extends MainModule {
  @override
  List<Bind> get binds => [
        Bind((i) => AppController()),
      ];

  @override
  List<ModularRouter.Router> get routers => [
        ModularRouter.Router(Modular.initialRoute, module: HomeModule()),
      ];

  @override
  Widget get bootstrap => AppWidget();

  static Inject get to => Inject<AppModule>.of();
}
sleepingkit
  • 598
  • 3
  • 8
  • Thank you so much. It worked. Who is new with flutter like me. I also had to change the inject and bind like this: ModularRouter.Inject, ModularRouter.Bind. And I changed the Modular.initialRoute to "/". – user6076 Aug 19 '20 at 13:42