https://github.com/devhammed/dartified
Life-saving helpers for working with JavaScript libraries when compiling Dart/Flutter to Web.
https://github.com/devhammed/dartified
Last synced: 6 months ago
JSON representation
Life-saving helpers for working with JavaScript libraries when compiling Dart/Flutter to Web.
- Host: GitHub
- URL: https://github.com/devhammed/dartified
- Owner: devhammed
- License: bsd-3-clause
- Created: 2022-08-19T12:09:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-19T12:16:15.000Z (over 3 years ago)
- Last Synced: 2025-02-12T07:20:13.181Z (about 1 year ago)
- Language: Dart
- Size: 4.88 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# dartified
Life-saving helpers for working with JavaScript libraries when compiling Dart/Flutter to Web.
## Features
The functions included in this library will only work when you are compiling a Dart/Flutter project to Web.
Below are the included helpers so far:
- `isBasicType(value)` - Checks if a value doesn't need to be converted between JavaScript and Dart.
- `dartify(dynamic object)` - Converts a JavaScript object to what can be used in Dart.
- `jsify(Object object)` - Converts a Dart object to what can be passed to JavaScript.
- `promiseToFuture(JsObject object)` - Converts a JavaScript Promise object to Dart's Future object.
## Usage
```dart
import 'dart:js' as js;
import 'package:dartified/dartified.dart';
/// An example using browser's fetch.
Future main() async {
try {
var response = await Dartified.promiseToFuture(
js.context.callMethod(
Dartified.jsify('fetch'),
[
Dartified.jsify(
'https://api.github.com/repos/javascript-tutorial/en.javascript.info/commits',
),
],
),
);
var json =
await Dartified.promiseToFuture(response.callMethod('json'));
print(Dartified.dartify(json));
} catch (e) {
print('error: $e');
}
}
```