zoukankan      html  css  js  c++  java
  • Flutter-function

     

    在Dart中不存在内部类,所以很多时候我们需要回调无法直接使用内部类。

    所以我们引入function,function有参数的我们定义dynamic主要是为了实现泛型调用原理。

    老规矩,先上代码:

    import 'package:yxk_app/net/request_util.dart';
    
    /// 方法定义类型(用于接口回调中使用)
    
    /// 无参数
    typedef ActionNoParam = void Function();
    
    /// 一个参数
    typedef ActionOneParam = void Function(dynamic t);
    
    ///两个参数
    typedef ActionTwoParam = void Function(dynamic o, dynamic t);
    
    /// 请求成功
    typedef ResponceSuccess = void Function(dynamic t);
    
    /// 请求失败
    typedef ResponceError = void Function(LogicError error);
    
    

    使用说明:

    PermissionUtils.showDialog(cxt, "权限提醒",
            "使用易小康之前,需要开启"电话权限"、"短信权限"、"存储权限",以确保账号登录安全和信息安全。
    
    请在设置-应用-易小康-权限中开启相关权限。",
            () {
          isShowDialog = false;
          Navigator.pop(cxt);
          PermissionHandler().openAppSettings();
        }, () {
          SystemChannels.platform.invokeMethod('SystemNavigator.pop');
        });
    
    /// 权限提示对话款
    static showDialog(BuildContext cxt, String title, String content,
          ActionNoParam ok, ActionNoParam cancel) {
        showCupertinoDialog<int>(
            context: cxt,
            builder: (cxt) {
              return CupertinoAlertDialog(
                title: Text(title),
                content: Text(content),
                actions: <Widget>[
                  CupertinoDialogAction(
                    child: Text("去开启"),
                    onPressed: () {
                      ok();
                    },
                  ),
                  CupertinoDialogAction(
                    child: Text("取消"),
                    onPressed: () {
                      cancel();
                    },
                  )
                ],
              );
            });
      }
  • 相关阅读:
    linux 共享内存 信号量 同步
    进程间通信 共享内存
    linux 多进程绑定问题
    C 语言调用python 脚本函数
    C 语言 和 python 调用 .so 文件
    好好学习
    three.js
    AMD、CMD、UMD 模块的写法
    webpack查缺补漏
    什么是 Web 服务器(server)
  • 原文地址:https://www.cnblogs.com/sundaysandroid/p/13554855.html
Copyright © 2011-2022 走看看