-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Saddam Sinatrya <[email protected]>
- Loading branch information
Showing
5 changed files
with
42 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
library util; | ||
|
||
import 'dart:js_interop'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:web/web.dart'; | ||
|
||
extension Uint8ListExtension on Uint8List { | ||
Future<ImageBitmap> toImageBitmap() async { | ||
final buffer = this; | ||
final blob = Blob([buffer.toJS].toJS); | ||
final bitmap = await window.createImageBitmap(blob).toDart; | ||
return bitmap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,8 @@ | ||
@JS() | ||
library window; | ||
|
||
import 'dart:html'; | ||
import 'dart:typed_data'; | ||
import 'package:web/web.dart'; | ||
import 'pica.dart'; | ||
|
||
import 'package:js/js.dart'; | ||
import 'package:js/js_util.dart'; | ||
|
||
@JS() | ||
@staticInterop | ||
class JSWindow {} | ||
|
||
extension JSWindowExtension on JSWindow { | ||
external Function get createImageBitmap; | ||
external Function get pica; | ||
} | ||
|
||
Future<ImageBitmap> convertUint8ListToBitmap(Uint8List buffer) async { | ||
final blob = Blob([buffer]); | ||
|
||
final result = await jsWindow.createImageBitmap(blob); | ||
final bitmap = await promiseToFuture(result); | ||
return bitmap; | ||
} | ||
|
||
JSWindow get jsWindow => window as JSWindow; | ||
|
||
extension FutureDynamicExtension on dynamic { | ||
Future<T> toFuture<T>() => promiseToFuture(this); | ||
extension WindowExtension on Window { | ||
external Pica pica(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters