Commit c2c0ba09 authored by ouxiang's avatar ouxiang

assets channel

parent 492fe1a9
import 'dart:async'; import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -14,20 +14,21 @@ class _AssestPlatformChannelState extends State<AssestPlatformChannel> { ...@@ -14,20 +14,21 @@ class _AssestPlatformChannelState extends State<AssestPlatformChannel> {
static const EventChannel eventChannel = static const EventChannel eventChannel =
EventChannel('GMAssetsEventChannelName'); EventChannel('GMAssetsEventChannelName');
String _batteryLevel = 'Battery level: unknown.'; Uint8List _imageData;
Object _imageData; String _tttt = 'ssss';
Future<void> _editPortrait() async { Future<void> _editPortrait() async {
String batteryLevel; Uint8List imageData;
try { try {
final int result = await methodChannel.invokeMethod('editPortrait'); final result = await methodChannel.invokeMethod('editPortrait');
batteryLevel = 'Battery level: $result%.'; imageData = result;
} on PlatformException { } on PlatformException {
batteryLevel = 'Failed to get battery level.'; imageData = null;
} }
setState(() { setState(() {
_batteryLevel = batteryLevel; _imageData = imageData;
_tttt = 'aaaaa';
}); });
} }
...@@ -38,16 +39,11 @@ class _AssestPlatformChannelState extends State<AssestPlatformChannel> { ...@@ -38,16 +39,11 @@ class _AssestPlatformChannelState extends State<AssestPlatformChannel> {
} }
void _onEvent(Object event) { void _onEvent(Object event) {
_imageData = event; setState(() {});
print(event.runtimeType);
Image.memory(event);
setState(() {
});
} }
void _onError(Object error) { void _onError(Object error) {
setState(() { setState(() {});
});
} }
@override @override
...@@ -64,7 +60,7 @@ class _AssestPlatformChannelState extends State<AssestPlatformChannel> { ...@@ -64,7 +60,7 @@ class _AssestPlatformChannelState extends State<AssestPlatformChannel> {
Column( Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text(_batteryLevel, key: const Key('editPortrait')), Text(_tttt, key: const Key('editPortrait')),
Padding( Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: RaisedButton( child: RaisedButton(
...@@ -90,12 +86,14 @@ class _AssestPlatformChannelState extends State<AssestPlatformChannel> { ...@@ -90,12 +86,14 @@ class _AssestPlatformChannelState extends State<AssestPlatformChannel> {
Widget _imageWidget(){ Widget _imageWidget(){
if (_imageData != null) { if (_imageData != null) {
return Image.memory(_imageData, return Image.memory(_imageData,
color: Colors.purple, // color: Colors.purple,
width: 200, width: 200,
height: 200, height: 200,
); );
}else{ }else{
return Text('i am not image'); return Center(
child: Text('I am not image'+_tttt),
);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment