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, "权限提醒",
"使⽤易⼩康之前,需要开启\"电话权限\"、\"短信权限\"、\"存储权限\",以确保账号登录安全和信息安全。\n\n请在设置-应⽤-易⼩康-权限中开启相关权限。",        () {
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();
},
)
],
alertdialog使用方法
);
});
}