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

Provider should consider exporting SingleChildWidget from Nested #887

Closed
rydmike opened this issue Sep 12, 2024 · 1 comment
Closed

Provider should consider exporting SingleChildWidget from Nested #887

rydmike opened this issue Sep 12, 2024 · 1 comment
Assignees
Labels
bug Something isn't working needs triage

Comments

@rydmike
Copy link

rydmike commented Sep 12, 2024

Describe the bug
When using lint rule always_specify_types together with depend_on_referenced_packages we are forced to add an import of package nested:

import 'package:nested/nested.dart';

to the file using a MultiProvider, to be able to specify the type of list with providers.

To Reproduce

To reproduce this issue you need the right linter combination, a sample repo with this it is provided further below. Sample is based on the Provider example.

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
// We have to add this import to be able to specify type <SingleChildWidget>
// However, since we do not use and have nested in our pubspec, it triggers:
// > The imported package 'nested' isn't a dependency of the importing package. depend_on_referenced_packages
// lint rule, forcing us to also add `nested` to our pubspec to be able to commit code without lint rules triggered.
import 'package:nested/nested.dart';
import 'package:provider/provider.dart';

void main() {
  runApp(

    MultiProvider(
      // We cannot add the type <SingleChildWidget> without adding:
      // import 'package:nested/nested.dart';
      // above, but Nested is not used directly and we should not have to add it to our
      // pubspec or import it. It is not in pubspec in this example, the import
      // still works as it is in cached deps via Provider's transitive deps
      providers: <SingleChildWidget>[
        ChangeNotifierProvider<Counter>(
          create: (BuildContext context) => Counter(),
        ),
      ],
      child: const MyApp(),
    ),
  );
}

Expected behavior
Expect to be able to specify the type of a MultiProvider's list of providers as type <SingleChildWidget> without adding the package nested to pubspec.yaml or importing it in a file using Multiprovider.

Current choice of Provider not exporting SingleChildWidget forces us to also add package nested to our pubspec.yaml and import it in files using MultiProvider. This works, but is a bit of a dependency import smell.

Sample repo:

https://github.com/rydmike/multi_provider_issue

with needed lint combination to trigger the issue preconfigured.

@rydmike rydmike added bug Something isn't working needs triage labels Sep 12, 2024
@rydmike
Copy link
Author

rydmike commented Sep 12, 2024

I see that Provider does support and import like

import 'package:provider/single_child_widget.dart';

but for some reason that did not come up as suggestion by IDE, but it works and solves the issue. Closing this.

@rydmike rydmike closed this as completed Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants