Repository: flutter
Issue: path_provider plugin's getExternalStorageDirectory() method
Labels: platform-android,p: path_provider,package,P2,team-android,triaged-android

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill our the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

<!--
     Please tell us exactly how to reproduce the problem you are running into.

     Please attach a small application (ideally just one main.dart file) that
     reproduces the problem. You could use https://gist.github.com/ for this.

     If the problem is with your application's rendering, then please attach
     a screenshot and explain what the problem is.
-->
getExternalStorageDirectory() returns /storage/emulated/0/Android/data/com.example.shop/files
instead of /storage/emulated/0
Because of this I'm not able to get the image in my gallery. Although if I add the path manually I'm able to store the image.
<!--
     Please tell us which target platform(s) the problem occurs (Android / iOS / Web / macOS / Linux / Windows)
     Which target OS version, for Web, browser, is the test system running?
     Does the problem occur on emulator/simulator as well as on physical devices?
-->

**Target Platform:**Andriod Pie
**Devices:** Both physical and emulator


## Code

<b>qr.dart</b>
```dart
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'dart:io';
import 'package:flutter/rendering.dart';
import 'package:path_provider/path_provider.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:http/http.dart' as http;

class DisplayQR extends StatelessWidget {
  List<String> shopDataObj = List<String>();
  DisplayQR(this.shopDataObj);
  GlobalKey globalKey = new GlobalKey();
  var bgColor = Colors.red;

  String formattedDate() {
    DateTime dateTime = DateTime.now();
    String dateTimeString = 'SaloonQR_' +
        dateTime.year.toString() +
        dateTime.month.toString() +
        dateTime.day.toString() +
        dateTime.hour.toString() +
        ':' +
        dateTime.minute.toString() +
        ':' +
        dateTime.second.toString() +
        ':' +
        dateTime.millisecond.toString() +
        ':' +
        dateTime.microsecond.toString();
    return dateTimeString;
  }

  requestPermission() async {
    Map<PermissionGroup, PermissionStatus> permissions =
        await PermissionHandler().requestPermissions([PermissionGroup.storage]);
    // print(permissions);
    return permissions;
  }

  checkPermission() async {
    PermissionStatus permission = await PermissionHandler()
        .checkPermissionStatus(PermissionGroup.storage);
    return permission;
  }

  Future<void> _captureAndSavePng() async {
    // print("clicked");
    try {
      RenderRepaintBoundary boundary =
          globalKey.currentContext.findRenderObject();
      ui.Image image = await boundary.toImage(pixelRatio: 5.0);
      // print(image.height);

      ByteData byteData =
          await image.toByteData(format: ui.ImageByteFormat.png);
      // if (!(await checkPermission())) await requestPermission();
      PermissionStatus req = await checkPermission();
      if (req != PermissionStatus.granted) print(requestPermission());
      Uint8List pngBytes = byteData.buffer.asUint8List();
      Directory directory = await getExternalStorageDirectory();
      // String path = directory.path;
      String path = '/storage/emulated/0';
      print(path);
      await Directory('$path/SaloonQr').create(recursive: true);
      File('$path/SaloonQr/${formattedDate()}.png')
          .writeAsBytesSync(pngBytes.buffer.asInt8List());
    } catch (e) {
      print("Error:" + e.toString());
    }
  }

  Future<void> _captureAndSharePng() async {
    // print("clicked" + bgColor);
    try {
      RenderRepaintBoundary boundary =
          globalKey.currentContext.findRenderObject();
      ui.Image image = await boundary.toImage(pixelRatio: 5.0);
      // print(image.height);

      ByteData byteData =
          await image.toByteData(format: ui.ImageByteFormat.png);
      Uint8List pngBytes = byteData.buffer.asUint8List();
      // print(pngBytes);
      final tempDir = await getTemporaryDirectory();
      final file = await new File('${tempDir.path}/image.png').create();
      await file.writeAsBytes(pngBytes);

      final channel = const MethodChannel('channel:me.shopqr.share/share');
      channel.invokeMethod('shareFile', 'image.png');
    } catch (e) {
      print(e.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    bgColor = Theme.of(context).scaffoldBackgroundColor;
    return Container(
      // color: const Color(0xFFFFFFFF),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          RepaintBoundary(
            key: globalKey,
            child: Container(
              color: bgColor,
              child: Column(
                children: <Widget>[
                  QrImage(
                    backgroundColor: bgColor,
                    data: shopDataObj.elementAt(1),
                    version: QrVersions.auto,
                    size: 250.0,
                  ),
                  Text(
                    shopDataObj.elementAt(0),
                    style: TextStyle(
                      fontSize: 25,
                    ),
                  ),
                ],
              ),
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              IconButton(
                icon: Icon(Icons.save_alt),
                onPressed: () => {
                  _captureAndSavePng(),
                  Fluttertoast.showToast(
                      msg: "Image Saved",
                      gravity: ToastGravity.BOTTOM,
                      timeInSecForIos: 3,
                      backgroundColor: Colors.black12,
                      textColor: Colors.black,
                      fontSize: 16.0),
                },
              ),
              IconButton(
                icon: Icon(Icons.share),
                onPressed: () => {
                  _captureAndSharePng(),
                },
              ),
            ],
          ),
        ],
      ),
    );
  }
}
```