permission

 

import 'package:flutter/material.dart';
import 'dart:io';
import 'dart:async';
import 'package:rxdart/rxdart.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart';
import 'package:permission_handler/permission_handler.dart';
//import 'package:simple_permissions/simple_permissions.dart';


void main() => runApp(MaterialApp(home: MyApp(),));

class MyApp extends StatelessWidget {
  DataBloc bloc;

  cp()async{
    
//    var per = await SimplePermissions.checkPermission(Permission.WriteExternalStorage);
    
    var per = await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);
    if(per!=PermissionStatus.granted){
      print('requested');
      await PermissionHandler().requestPermissions([PermissionGroup.storage]);
    }
    per = await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);
    print('per: $per');

    Directory tempDir = await getExternalStorageDirectory();
    print(tempDir.path);
    print('start cp');
    String a = join(tempDir.path, '4');

    var p = await Process.run('mkdir', [a]).then((ProcessResult e){
      print(e.stdout);
      print(e.stderr);
      print(e.exitCode);
    });
    print('cp finished');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('sss'),),
      body: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            RaisedButton(child: Text('mkdir'),onPressed: (){

                cp();
            },),
            RaisedButton(child: Text('delete'),onPressed: (){

            },),
          ],
        ),
      ),
    );
  }
}

class DataBloc {
  ReplaySubject dataBloc = ReplaySubject();
}

//void shell(String cmd, List<String> opts, void onExit(int exitCode))async{
//  var p = await Process.start(cmd, opts);
//  p.stdout.pipe(stdout);
//  stdin.pipe(p.stdin);
//  p.onExit = (exitCode)async{
//    await p.kill();
//    onExit(exitCode);
//  }
//}


//void shell(String cmd, List<String> opts, void onExit(int exitCode)) {
//  var p = Process.start(cmd, opts);
//  p.stdout.pipe(stdout);  // Process output to stdout.
//  stdin.pipe(p.stdin);    // stdin to process input.
//  p.onExit = (exitCode) {
//    p.close();
//    onExit(exitCode);
//  };
//}

  

posted @ 2019-05-20 13:52  CrossPython  阅读(257)  评论(0编辑  收藏  举报