education 0.2.2
education: ^0.2.2 copied to clipboard
android api
example/lib/main.dart
import 'package:education/education.dart';
import 'package:education_example/page/global_var.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
print("测试代码");
print(GlobalVar.c); // 输出: 1
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final _educationPlugin = Education();
static const platform = MethodChannel('android_call_flutter');
@override
void initState() {
super.initState();
platform.setMethodCallHandler((MethodCall call) async {
switch (call.method) {
case 'onDataReceived':
String data = call.arguments as String;
// Handle the data and do something
print(data);
// 返回给 android 响应信息
return "Data processed";
default:
throw MissingPluginException();
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Column(
children: [
GestureDetector(
onTap: () async {
var imageString = await _educationPlugin.getGalleryImage();
print(imageString);
},
child: Container(
width: 200,
height: 200,
color: Colors.deepOrange,
),
),
],
),
);
}
}