flutterdart

Enable hot reload inside a package inside flutter project


I am Building a flutter project where its structure like this

app/
   lib/
      packages/
              my_package

when i import the package inside my app pubspec.yaml like this:

  my_package:
    path: "lib/packages/my_package"

and then import it and use it, when the app is running and i make a modifications inside this package, the app will not responds to these modifications until I stop the app and re-run it again


Solution

  • You can do the next in VS Code:

    1. Create a parent folder for the main project and the packages
    - parent_folder
       - main_project
       - packages
          - package_1
          - package_2
    
    1. In the parent folder create a file .vscode/launch.json
    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "project_name",
                "request": "launch",
                "type": "dart",
                "cwd": "main_project",
                "program": "lib/main.dart",
            }
        ]
    }
    

    And with this when you save a change on your package, you main project will be loaded with it