Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter module get dependencies used into another module

I'm developing a Flutter project to study modularization. So, for the first time, I'm setting the project with core, design and feature modules, besides the project module. I'm gonna use provider for dependency injection and state management and mockito for testing, and, like in Android development, I tried to put these dependencies inside core module, and my feature module uses this core module. But inside my feature module I cant access either, mockito and provider. There is a way to do that?

this is my feature module pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  core:
    path: ../core
  design_system:
    path: ../design_system
  network:
    path: ../network

and this is my core module pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter

  connectivity: ^3.0.6
  provider: ^5.0.0

dev_dependencies:
  mockito: ^5.0.0
  flutter_test:
    sdk: flutter
like image 342
Murillo Maciel Avatar asked Mar 22 '26 04:03

Murillo Maciel


1 Answers

You will need to export the packages from a file in the core module. As mockito is a dev dependency you cant export it, but you can add it as a dev dependency in the other project.

in core/core.dart

export 'package:provider/provider.dart'
export 'package:connectivity/connectivity.dart'

For a real-world use case take a look at the material or cupertino packages in the flutter framework github repository

like image 84
Rohan Thacker Avatar answered Mar 23 '26 19:03

Rohan Thacker