You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.9 KiB
69 lines
1.9 KiB
//各种封装的小函数
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:bruno/bruno.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
void toast(String msg, BuildContext context){
|
|
BrnToast.show(msg, context);
|
|
}
|
|
|
|
String formattedTime(int timestamp){
|
|
|
|
|
|
// 使用DateTime.fromMillisecondsSinceEpoch来创建DateTime对象
|
|
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp, isUtc: false);
|
|
|
|
// 手动格式化日期和时间
|
|
String formattedDateTime = '${dateTime.year}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}';
|
|
return formattedDateTime;
|
|
}
|
|
|
|
|
|
|
|
Future<bool> handlePermission(BuildContext context, String content) async {
|
|
PermissionStatus status;
|
|
status = await Permission.location.status;
|
|
|
|
final Completer<bool> completer = Completer<bool>();
|
|
|
|
if (status.isDenied) {
|
|
// 如果没有权限,显示权限提示弹窗
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text("提示"),
|
|
content: Text(content),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
child: Text("确定"),
|
|
onPressed: () async {
|
|
Map<Permission, PermissionStatus> statuses;
|
|
statuses = await [
|
|
Permission.location,
|
|
].request();
|
|
|
|
Navigator.of(context).pop();
|
|
completer.complete(true);
|
|
},
|
|
),
|
|
TextButton(
|
|
child: Text("取消"),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
completer.complete(false);
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
} else {
|
|
completer.complete(true);
|
|
}
|
|
|
|
return completer.future;
|
|
}
|