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

[connectivity_plus] naming collision in generated_plugin_registrant when [connectivity] is a transitive dependency #260

Closed
ol88 opened this issue May 28, 2021 · 2 comments
Assignees
Labels
bug Something isn't working connectivity_plus Connectivity Plus

Comments

@ol88
Copy link

ol88 commented May 28, 2021

System info

Issue occurs on: web
Plugin name: connectivity_plus
Plugin version: 1.0.1
Flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel dev, 2.2.0-11.0.pre.2, on Microsoft Windows [Version 10.0.19042.985], locale en-AU)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 3.6)
[√] VS Code (version 1.56.2)
[√] Connected device (3 available)

Steps to Reproduce

  1. Have a web enabled flutter app.
  2. Have an existing transitive dependency to the connectivity package (for example using graphql_flutter: ^5.0.0-nullsafety.5) which itself depends on connectivity_for_web.
  3. Add connectivity_plus as a direct dependency to the app.
  4. Let the automatically generated file generated_plugin_registrant.dart be generated and open it.

An error is generated in because registerPlugins in generated_plugin_registrant.dart tries to register both ConnectivityPlugin from two different packages, one from connectivity_for_web and one from connectivity_plus_web.

Ideally, the naming collision should be avoided by connectivity_plus as we cannot expect all packages depending on connectivity to migrate to connectivity_plus.

pubspec.yaml:

[...]
dependencies:
  flutter:
    sdk: flutter

  graphql_flutter: ^5.0.0-nullsafety.5
  connectivity_plus: ^1.0.1
[...]

main.dart (default app):

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Test'),
        ),
        body: Container());
  }
}

generated_plugin_registrant.dart:

//
// Generated file. Do not edit.
//

// ignore_for_file: lines_longer_than_80_chars

import 'package:connectivity_for_web/connectivity_for_web.dart';
import 'package:connectivity_plus_web/connectivity_plus_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
  ConnectivityPlugin.registerWith(registrar);
  ConnectivityPlugin.registerWith(registrar);
  registrar.registerMessageHandler();
}

Analysis Error

The name 'ConnectivityPlugin' is defined in the libraries 'package:connectivity_for_web/connectivity_for_web.dart' and 'package:connectivity_plus_web/connectivity_plus_web.dart'.
Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.
@mhadaily
Copy link
Member

mhadaily commented Jun 7, 2021

@ol88 we have released a new version, can you give it a try?

@ol88
Copy link
Author

ol88 commented Jun 7, 2021

@mhadaily Works great thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working connectivity_plus Connectivity Plus
Projects
None yet
Development

No branches or pull requests

3 participants