muxinplugin 0.0.2
muxinplugin: ^0.0.2 copied to clipboard
This plug-in is used to test how to make a plug-in. If you need it, you can go to study it. If you don't need it, please ignore me, This plug-in is used to test how to make a plug-in. If you need it, [...]
example/lib/main.dart
import 'dart:convert';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:muxinplugin/muxinplugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final _muxinpluginPlugin = Muxinplugin.instance;
int? add;
int? reduce;
int? muti;
int? div;
String? countString;
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion =
await _muxinpluginPlugin.getPlatformVersion() ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
int addResult = await _muxinpluginPlugin.add(10, 20);
add = addResult;
int reduceResult = await _muxinpluginPlugin.reduce(10, 20);
reduce = reduceResult;
int mutiRe = await _muxinpluginPlugin.muti(2, 3);
muti = mutiRe;
int divRe = await _muxinpluginPlugin.div(30, 2);
div = divRe;
print("------>>addResult:$addResult, reduceResult:$reduceResult, mutiRe:$mutiRe, divRe:$divRe");
_muxinpluginPlugin.onMessageRecive(suCallBack: (data) {
if(data is String){
Map<String, dynamic> mapData = json.decode(data);
if(mapData.containsKey("key")){
String key = mapData["key"];
if(key == "addCount"){
String value = mapData["value"];
setState(() {
countString = value;
});
}
}
}
},errCallBack: (error) {
},);
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("${add.toString()}"),
SizedBox(height: 40,),
Text("${reduce.toString()}"),
SizedBox(height: 40,),
Text("${muti.toString()}"),
SizedBox(height: 40,),
Text("${div.toString()}"),
SizedBox(height: 40,),
ElevatedButton(onPressed: () async{
await _muxinpluginPlugin.addCount();
}, child: Text("点击计数:$countString")),
SizedBox(height: 40,),
ElevatedButton(onPressed: () async{
await _muxinpluginPlugin.pause();
}, child: Text("暂停计数")),
],
),
),
),
);
}
}