SAF测试阶段,验证中
This commit is contained in:
@@ -283,18 +283,23 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
final ctx = context;
|
||||
Navigator.pop(ctx);
|
||||
// 触发关闭
|
||||
Navigator.pop(context);
|
||||
|
||||
// 延迟确保动画完成
|
||||
await Future.delayed(const Duration(milliseconds: 150));
|
||||
|
||||
final result = await _safService.requestPermission();
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (result.success) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_safState = SafPermissionState.authorized;
|
||||
});
|
||||
readBatteryCapacity();
|
||||
} else {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(ctx).showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(result.errorMessage ?? '授权失败,请重试'),
|
||||
backgroundColor: Colors.red,
|
||||
@@ -303,7 +308,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
|
||||
_showSafAuthorizationDialog();
|
||||
}
|
||||
},
|
||||
child: const Text('选择文件夹'), // 🟢 加这行
|
||||
child: const Text('选择文件夹'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -774,6 +779,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await _safService.init();
|
||||
_safState = await _safService.getPermissionState();
|
||||
|
||||
if (_safState == SafPermissionState.unauthorized ||
|
||||
_safState == SafPermissionState.expired) {
|
||||
if (mounted) _showSafAuthorizationDialog();
|
||||
|
||||
Reference in New Issue
Block a user