美文网首页
Flutter Plugins

Flutter Plugins

作者: 落寞1990 | 来源:发表于2023-08-21 16:52 被阅读0次

1、Flutter Plugins编译中的 exit code 各自代表什么情况
exit code 0 表示程序执行成功,正常退出
exit code 1 表示程序执行执行过程中遇到了某些问题或者错误,非正常退出
exit code -1 表示程序执行执行过程中遇到了某些问题或者错误,非正常退出
2、flutter_inappwebview 插件的使用
插件地址:
https://pub-web.flutter-io.cn/packages/flutter_inappwebview/install

 Expanded(
                child: InAppWebView(
              initialUrlRequest: URLRequest(
                  url: Uri.parse(
                      "https://www.phonegap100.com/newscontent.php?aid=${widget.arguments["aid"]}")),
              onProgressChanged: (controller, progress) {
                print(progress / 100);
                if (progress / 100 > 0.999) {
                  setState(() {
                    showLoading = true;
                  });
                }
              },
            ))

Android 注意事项
1、minSdkVersion 17
2、添加<uses-permission android:name="android.permission.INTERNET"/>
Ios注意事项
后端配置苹果支持的https证书
3、device_info_plus 插件获取设备信息

getDeviceInfo() async {
    final deviceInfoPlugin = DeviceInfoPlugin();
    final deviceInfo = await deviceInfoPlugin.deviceInfo;
    final deviceInfoMap = deviceInfo.toMap();
    var templist = deviceInfoMap.entries.map((e) {
      return ListTile(
        title: Text("${e.key}:${e.value}"),
      );
    }).toList();
    setState(() {
      list = templist;
    });
  }

4、connectivity_plus 检测网络

dynamic subscription;
  String stateText = "检测中...";
  @override
  void initState() {
    super.initState();
    subscription = Connectivity()
        .onConnectivityChanged
        .listen((ConnectivityResult result) {
      if (result == ConnectivityResult.wifi) {
        setState(() {
          stateText = "处于 wifi";
        });
      } else if (result == ConnectivityResult.bluetooth) {
        setState(() {
          stateText = "处于蓝牙";
        });
      } else if (result == ConnectivityResult.mobile) {
        setState(() {
          stateText = "处于手机网络";
        });
      } else {
        setState(() {
          stateText = "没有网络";
        });
      }
    });
  }

5、url_launcher 配置打开URL、拨打电话 、发送短信 、打开外部应用、打开高德地图
Android配置

 <!-- 拨打电话 打开外部app的配置 开始 -->
      <!-- Provide required visibility configuration for API level 30 and above -->
    <queries>
    <!-- If your app checks for SMS support -->
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="sms" />
    </intent>
    <!-- If your app checks for call support -->
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="tel" />
    </intent>
    </queries>
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>

IOS配置

<key>LSApplicationQueriesSchemes</key>
<array>
<string>iosamap</string>
<string>baidumap</string>
<string>sms</string>
<string>tel</string>
<string>weixin</string>
<string>alipays</string>
</array
return Scaffold(
        appBar: AppBar(
          title: const Text('Device演示'),
        ),
        body: Center(
            child: Padding(
          padding: const EdgeInsets.all(20),
          child: ListView(children: [
            ElevatedButton(
              child: const Text('打开外部浏览器'),
              onPressed: () async {
                final Uri url = Uri.parse('https://www.itying.com');
                if (await canLaunchUrl(url)) {
                  await launchUrl(url);
                } else {
                  throw 'Could not launch $url';
                }
              },
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              child: const Text('拨打电话'),
              onPressed: () async {
                final Uri tel = Uri.parse('tel:10086');
                if (await canLaunchUrl(tel)) {
                  await launchUrl(tel);
                } else {
                  throw 'Could not launch $tel';
                }
              },
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              child: const Text('发送短信'),
              onPressed: () async {
                final Uri tel = Uri.parse('sms:10086');
                if (await canLaunchUrl(tel)) {
                  await launchUrl(tel);
                } else {
                  throw 'Could not launch $tel';
                }
              },
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              child: const Text('打开外部应用-支付宝'),
              onPressed: () async {
                final Uri alipays = Uri.parse('alipays://');
                if (await canLaunchUrl(alipays)) {
                  await launchUrl(alipays);
                } else {
                  throw 'Could not launch $alipays';
                }
              },
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              child: const Text('打开外部应用-微信'),
              onPressed: () async {
                final Uri weixin = Uri.parse('weixin://');
                if (await canLaunchUrl(weixin)) {
                  await launchUrl(weixin);
                } else {
                  throw 'Could not launch $weixin';
                }
              },
            ),
            const SizedBox(height: 10),
            ElevatedButton(
                child: const Text('打开外部应用-百度地图'),
                onPressed: () async {
                  String title = "北京大学";
                  String latitude = "39.992806";
                  String longitude = "116.310905";
                  //高德地图
                  // Uri  uri = Uri.parse(
                  //       '${Platform.isAndroid ? 'android' : 'ios'}amap://navi?sourceApplication=amap&lat=$latitude&lon=$longitude&dev=0&style=2&poiname=${title}');
                  //百度地图
                  Uri uri = Uri.parse(
                      "baidumap://map/direction?destination=name:$title|latlng:$latitude,$longitude&coord_type=bd09ll&mode=driving");
                  try {
                    if (await canLaunchUrl(uri)) {
                      await launchUrl(uri);
                    } else {
                      print('无法调起高德地图');
                    }
                  } catch (e) {
                    print('无法调起高德地图');
                  }
                }),
          ]),
        )));

相关文章

网友评论

      本文标题:Flutter Plugins

      本文链接:https://www.haomeiwen.com/subject/kwxymdtx.html