nan_common_utils 0.0.21 nan_common_utils: ^0.0.21 copied to clipboard
A new Flutter project.
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:nan_common_utils/nan_common_utils.dart';
import 'package:nan_common_utils/nan_util.dart';
const VIEW_TYPE = 'com.amap.flutter.map';
const BasicMessageChannel<dynamic> messageChannel = const BasicMessageChannel("testDidiView2", StandardMessageCodec());
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String address="地址";
@override
void initState() {
super.initState();
initPlatformState();
messageChannel.setMessageHandler((message)async{
// setState(() {
// address = message.address;
// });
// NanUtil.showUploadDialog(context,tipMsg: "正在加载中...");
setState(() {
address = message["address"];
});
});
}
// 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 NanCommonUtils.platformVersion ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// 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'),
actions: [
new Builder(
builder: (context){
return InkWell(
child: Container(
margin: EdgeInsets.only(right: 10),
alignment: Alignment.center,
child: Text("确定"),
),
onTap: (){
messageChannel.send({"method":'haha'});
},
);
},
)
],
),
// body: Center(
// child: Text('Running on: $_platformVersion\n'),
// ),
body: Column(
children: [
Container(
child: Text("$address",style: TextStyle(fontSize: 20),),
width: NanUtil.kScreenWidth,
constraints: BoxConstraints(
minHeight: 20
),
),
Expanded(child: SizedBox(
width: NanUtil.kScreenWidth,
height: 200,
child: Platform.isIOS?UiKitView(
viewType: VIEW_TYPE,
// onPlatformViewCreated: onPlatformViewCreated,
// gestureRecognizers: gestureRecognizers,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
):AndroidView(
viewType: VIEW_TYPE,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
),
))
],
),
),
);
}
final Map<String, dynamic> creationParams = <String, dynamic>{
'apiKey': "您的appkey",
};
}