mirror of https://github.com/flutter/samples.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
968 B
29 lines
968 B
// Copyright 2020 The Flutter team. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
/// This class manages a [BasicMessageChannel] that can return an image loaded
|
|
/// from a native asset. The [BasicMessageChannel] uses [StandardMessageCodec]
|
|
/// since it supports [Uint8List], which is used to transport the image data.
|
|
class PlatformImageFetcher {
|
|
static const _basicMessageChannel = BasicMessageChannel<dynamic>(
|
|
'platformImageDemo',
|
|
StandardMessageCodec(),
|
|
);
|
|
|
|
/// Method responsible for providing the platform image.
|
|
static Future<Uint8List> getImage() async {
|
|
final reply = await _basicMessageChannel.send('getImage') as Uint8List?;
|
|
if (reply == null) {
|
|
throw PlatformException(
|
|
code: 'Error',
|
|
message: 'Failed to load Platform Image',
|
|
details: null,
|
|
);
|
|
}
|
|
return reply;
|
|
}
|
|
}
|