# hotreloader 3.0.6

Automatic hot code reloader for Dart projects that monitors the source files of a Dart project for changes and automatically applies them to the running Dart process.





## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'hotreloader:3.0.6'
```
Published: 2023-04-03T13:30:12.804535Z
Expected archive SHA-256: 728c0613556c1d153f7e7f4a367cffacc3f5a677d7f6497a1c2b35add4e6dacf

Available in cache; verification: upstream_checksum
## Direct dependencies
- collection: ^1.15.0
- logging: ^1.0.0
- path: ^1.8.0
- stream_transform: ^2.0.0
- vm_service: >=6.0.1 <12.0.0
- watcher: ^1.0.0

## Package README (untrusted upstream documentation)
# hotreloader (Dart)

[![Build Status](https://github.com/vegardit/dart-hotreloader/workflows/Build/badge.svg "GitHub Actions")](https://github.com/vegardit/dart-hotreloader/actions?query=workflow%3ABuild)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE.txt)
[![Pub Package](https://img.shields.io/pub/v/hotreloader.svg)](https://pub.dev/packages/hotreloader)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)

1. [What is it?](#what-is-it)
1. [Requirements](#requirements)
1. [How to use](#how-to-use)
1. [Logging](#logging)
1. [Alternatives](#alternatives)
1. [Changelog / Version History](#changelog)
1. [License](#license)


## <a name="what-is-it"></a>What is it?

This [Dart](https://dart.dev) library provides a code reloading service that monitors the source files of a Dart project on the local file system for changes
and automatically applies them using the Dart VM's [hot reload](https://github.com/dart-lang/sdk/wiki/Hot-reload) capabilities to the running Dart process.


## <a name="requirements"></a>Requirements

hotreloader 1.x-2.x requires [Dart SDK](https://dart.dev/get-dart) **2.6.0** or higher.

hotreloader 3.x requires [Dart SDK](https://dart.dev/get-dart) **2.12.0** or higher.


## <a name="how-to-use"></a>How to use

1. Add hotreloader to your dev dependencies using this command

   ```sh
   dart pub add --dev hotreloader
   ```

   or by adding this to your `pubspec.yaml`:

   ```yaml
   dev_dependencies:
     hotreloader: ^3.0.4
   ```

1. Enable hot reloading in your entry point dart file, e.g. `bin/main.dart`

   ```dart
   import 'package:hotreloader/hotreloader.dart';

   Future<void> main(List<String> args) async {

     // instantiate a reloader that by monitors the project's source code folders for changes
     final reloader = await HotReloader.create();

     // ... your other code

     // cleanup
     reloader.stop();
   }
   ```

1. Run the dart program using the Dart VM with the `--enable-vm-service` flag enabled, e.g.

   ```bash
   dart --enable-vm-service bin/main.dart
   ```

1. You can now change dart files under the `lib` and the changes should be applied to the running process.

The reloader service can be further customized, e.g.

```dart
import 'package:hotreloader/hotreloader.dart';

Future<void> main(List<String> args) async {

  final reloader = await HotReloader.create(
    debounceInterval: Duration(seconds: 2), // wait up to 2 seconds after file change before reloading
    onBeforeReload: (ctx) =>
      ctx.isolate.name != 'foobar' && // never reload the isolate named 'foobar'
      ctx.event?.path.contains('/mymodel/')) ?? true, // only perform reload when dart files under ../mymodel/ are changed
    onAfterReload: (ctx) => print('Hot-reload result: ${ctx.result}')
  );

  // ... your other code

  await reloader.reloadCode(); // programmatically trigger code reload

  // ... your other code

  // cleanup
  reloader.stop();
}
```


## <a name="logging"></a>Logging

This library uses the [logging](https://pub.dev/packages/logging) package for logging.

You can configure the logging framework and change the [log-level](https://github.com/dart-lang/logging/blob/master/lib/src/level.dart) programmatically like this:

```dart
import 'dart:io' as io;
import 'dart:isolate';
import 'package:hotreloader/hotreloader.dart';
import 'package:logging/logging.dart' as logging;

Future<void> main() async {
  logging.hierarchicalLoggingEnabled = true;
  // print log messages to stdout/stderr
  logging.Logger.root.onRecord.listen((msg) =>
    (msg.level < logging.Level.SEVERE ? io.stdout : io.stderr)
    .write('${msg.time} ${msg.level.name} [${Isolate.current.debugName}] ${msg.loggerName}: ${msg.message}\n')
  );


  HotReloader.logLevel = logging.Level.CONFIG;

  final reloader = await HotReloader.create();

  // ... your other code

  // cleanup
  reloader.stop();
}
```


## <a name="alternatives"></a>Alternatives

- https://pub.dev/packages/angel_hot (last update 05/2019)
- https://pub.dev/packages/jaguar_hotreload (last update 02/2019)
- https://pub.dev/packages/recharge
- https://pub.dev/packages/reloader (last update 01/2019)


## <a name="changelog"></a>Changelog / Version History

This project maintains a [changelog](CHANGELOG.md) and adheres to [Semantic Versioning](https://semver.org) and [Keep a CHANGELOG](https://keepachangelog.com)


## <a name="license"></a>License

All files are released under the [Apache License 2.0](LICENSE.txt).

Individual files contain the following tag instead of the full license text:
```
SPDX-License-Identifier: Apache-2.0
```

This enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/.
## Changelog
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased]


## [3.0.6] - 2023-04-03

### Changed
- support vm_service 11.x


## [3.0.5] - 2022-07-11

### Changed
- support vm_service 9.x


## [3.0.4] - 2022-04-25

### Fixed
- [#9](https://github.com/vegardit/dart-hotreloader/issues/9) multiple directories starting with same characters are not watched


## [3.0.3] - 2022-03-20

### Fixed
- [#6](https://github.com/vegardit/dart-hotreloader/issues/6) Awaiting HotReloader.stop() causes program to wait forever

### Changed
- support vm_service 8.x


## [3.0.2] - 2022-01-04

### Changed
- support vm_service 7.x


## [3.0.1] - 2021-04-18

### Changed
- improve file watching
- replace some sync calls with async calls


## [3.0.0] - 2021-03-16

### Added
- enable null safety support

### Changed
- require Dart 2.12.0 for null safety support
- upgrade dependencies:
  - logging 1.0.0
  - path 1.8.0
  - stream_transform 2.0.0
  - vm_service 6.1.0+1
  - watcher 1.0.0


## [2.0.2] - 2020-10-19

### Added
- support version 5.x of vm_service library


## [2.0.1] - 2020-10-18

## Fixed
- `FormatException: Scheme not starting with alphabetic character` with Dart 2.9 or higher


## [2.0.0] - 2020-04-09

## Added
- watch dependencies for source code changes

### Changed
- support slightly older versions of dependencies


## [1.0.0] - 2020-04-08
- initial release







 
