添加依赖
permission_handler: ^3.2.2
androidmanifest.xml添加对应的用户权限
在flutter 中app入口申请权限:
import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:permission_handler/permission_handler.dart'; import 'users.dart'; Future main() async { if (!await _requestPermissions()) { await AppUtils.popApp(); } else { runApp(new MyApp()); } } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { final appTitle = "flutter demo"; return new MaterialApp( title: appTitle, home: new JobPage(), ); } } Future<bool> _requestPermissions() async { Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([ PermissionGroup.storage, PermissionGroup.location, ]); List<bool> results = permissions.values.toList().map((status) { return status == PermissionStatus.granted; }).toList(); return !results.contains(false); } class AppUtils { static Future<void> popApp() async { await SystemChannels.platform.invokeMethod('SystemNavigator.pop'); } static Future checkUpgrade() async { try { final bool result = await ApplicationMethodChannel.main.invokeMethod('checkUpgrade'); print('result=$result'); } on PlatformException { print('faied'); } } } class ApplicationMethodChannel { static MethodChannel main = MethodChannel('main'); }