Commit 0d913eab authored by ouxiang's avatar ouxiang

add assets channel

parent cd6b1d7d
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class PlatformChannel extends StatefulWidget {
@override
_PlatformChannelState createState() => _PlatformChannelState();
}
class _PlatformChannelState extends State<PlatformChannel> {
static const MethodChannel methodChannel =
MethodChannel('GMAssetsMethodChannelName');
static const EventChannel eventChannel =
EventChannel('GMAssetsEventChannelName');
String _batteryLevel = 'Battery level: unknown.';
ByteData _imageData;
Future<void> _editPortrait() async {
String batteryLevel;
try {
final int result = await methodChannel.invokeMethod('editPortrait');
batteryLevel = 'Battery level: $result%.';
} on PlatformException {
batteryLevel = 'Failed to get battery level.';
}
setState(() {
_batteryLevel = batteryLevel;
});
}
@override
void initState() {
super.initState();
eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);
}
void _onEvent(Object event) {
_imageData = event;
print(event.runtimeType);
setState(() {
});
}
void _onError(Object error) {
setState(() {
});
}
@override
Widget build(BuildContext context) {
return Material(
child: Scaffold(
appBar: AppBar(
title: Text('editPortrait test'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(_batteryLevel, key: const Key('editPortrait')),
Padding(
padding: const EdgeInsets.all(16.0),
child: RaisedButton(
child: const Text('editPortrait'),
onPressed: _editPortrait,
),
),
],
),
],
),
),
),
);
}
}
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