From f07c39a2e83a08323ea89270ec11c34523b64edc Mon Sep 17 00:00:00 2001 From: Ali Ghassemi Date: Tue, 3 Nov 2015 08:52:21 -0800 Subject: [PATCH] Adding RawImage component which takes in raw bytes in the form of a Uint8List and decodes and renders the bytes as an image. --- packages/flutter/lib/src/widgets/basic.dart | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index e79f9013a6f..be8798a5483 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:typed_data'; import 'dart:ui' as ui; import 'package:flutter/rendering.dart'; @@ -1095,6 +1096,39 @@ class DefaultAssetBundle extends InheritedWidget { bool updateShouldNotify(DefaultAssetBundle old) => bundle != old.bundle; } +class RawImage extends StatelessComponent { + RawImage( + {Key key, + this.bytes, + this.width, + this.height, + this.colorFilter, + this.fit, + this.repeat: ImageRepeat.noRepeat, + this.centerSlice}) + : super(key: key); + + final Uint8List bytes; + final double width; + final double height; + final ColorFilter colorFilter; + final ImageFit fit; + final ImageRepeat repeat; + final Rect centerSlice; + + Widget build(BuildContext context) { + ImageResource image = new ImageResource(decodeImageFromList(bytes)); + return new ImageListener( + image: image, + width: width, + height: height, + colorFilter: colorFilter, + fit: fit, + repeat: repeat, + centerSlice: centerSlice); + } +} + class AssetImage extends StatelessComponent { AssetImage({ Key key,