美文网首页Flutter
flutter-permission-handler(Flutt

flutter-permission-handler(Flutt

作者: Obadiah | 来源:发表于2019-05-13 22:55 被阅读551次

    https://github.com/BaseflowIT/flutter-permission-handler


    
    import 'package:flutter/material.dart';
    
    import 'package:permission_handler/permission_handler.dart';
    
    import 'package:fluttertoast/fluttertoast.dart';
    
    void main() => runApp(MaterialApp(
    
          home: HomePage(),
    
        ));
    
    class HomePage extends StatelessWidget {
    
      @override
    
      Widget build(BuildContext context) {
    
        return new Scaffold(
    
          appBar: new AppBar(
    
            title: new Text('Welcome to Flutter'),
    
          ),
    
          body: new Center(
    
            child: new RaisedButton(
    
              onPressed: () {
    
                requestPermission();
    
              },
    
              child: Text("hello"),
    
            ),
    
          ),
    
        );
    
      }
    
    }
    
    Future requestPermission() async {
    
      // 申请权限
    
      Map<PermissionGroup, PermissionStatus> permissions =
    
          await PermissionHandler().requestPermissions([PermissionGroup.storage]);
    
      // 申请结果
    
      PermissionStatus permission =
    
          await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);
    
      if (permission == PermissionStatus.granted) {
    
        Fluttertoast.showToast(msg: "权限申请通过");
    
      } else {
    
        Fluttertoast.showToast(msg: "权限申请被拒绝");
    
      }
    
    }
    
    

    相关文章

      网友评论

        本文标题:flutter-permission-handler(Flutt

        本文链接:https://www.haomeiwen.com/subject/mpvdaqtx.html