My Flutter App is Not Working on Android 11 But Working fine in emulator as well as android 8 || (OS Error: Operation not permitted, errno = 1)

My Flutter App is Not Working on Android 11 But Working fine in emulator as well as android 8 || (OS Error: Operation not permitted, errno = 1)

这是我的代码

import 'package:flutter/material.dart';
import 'package:screenshot/screenshot.dart';
import 'package:sweld/globals.dart';
import 'package:geolocator/geolocator.dart';

class WeldSetup extends StatelessWidget {
  WeldSetup({Key? key}) : super(key: key);
  final pageNum = 211;

  @override
  Widget build(BuildContext context) {
    final _ssc = ScreenshotController();
    return Scaffold(
      appBar: AppBar(
        title: Text("Weld Setup"),
        centerTitle: true,
        actions: [
          IconButton(
            onPressed: () {
              Navigator.pop(context);
            },
            icon: Icon(Icons.railway_alert_rounded),
          ),
        ],
      ),
      body: Screenshot(controller: _ssc, child: WsLocation()),
      persistentFooterButtons: [
        ElevatedButton(
            onPressed: () async {
              Globals.ss211 = await _ssc.captureAndSave(Globals.appDir,
                  fileName: "ss211.png",
                  pixelRatio: MediaQuery.of(context).devicePixelRatio,
                  delay: Duration(milliseconds: 100));

              Navigator.pushNamed(context, "/212");
            },
            child: Text("Next"))
      ],
      extendBody: true,
    );
  }
}

class WsLocation extends StatefulWidget {
  const WsLocation({Key? key}) : super(key: key);

  @override
  _WsLocationState createState() => _WsLocationState();
}

class _WsLocationState extends State<WsLocation> {
  late Position curPos;
  var longitute = Globals.longitude;
  var latitude = Globals.latitude;
  TimeOfDay sTime = TimeOfDay(hour: 00, minute: 00);
  TimeOfDay eTime = TimeOfDay(hour: 00, minute: 00);

  Widget selectTime(time) {
    if (time == TimeOfDay(hour: 00, minute: 00)) {
      return Text("Select Time");
    } else {
      if (time == sTime) {
        return Text("${Globals.stime}");
      } else {
        return Text("${Globals.etime}");
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
        margin: EdgeInsets.all(15),
        color: Colors.white,
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  "LOCATION",
                  textScaleFactor: 2,
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                  ),
                )
              ],
            ),
            Divider(
              thickness: 2,
              height: 50,
            ),
            Container(
              child: Form(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        Flexible(
                          child: TextFormField(
                            initialValue: Globals.longitude,
                            decoration: InputDecoration(
                              labelText: "Longitude",
                              border: OutlineInputBorder(
                                borderRadius: BorderRadius.circular(5),
                                borderSide: BorderSide(
                                  color: Colors.black,
                                  style: BorderStyle.solid,
                                  width: 1.5,
                                ),
                              ),
                            ),
                            onChanged: (val) {
                              setState(() {
                                Globals.longitude = val;
                              });
                            },
                          ),
                        ),
                        Divider(
                          indent: 5,
                        ),
                        Flexible(
                          child: TextFormField(
                            initialValue: Globals.latitude,
                            decoration: InputDecoration(
                              labelText: "Latitude",
                              border: OutlineInputBorder(
                                borderRadius: BorderRadius.circular(5),
                                borderSide: BorderSide(
                                  color: Colors.black,
                                  style: BorderStyle.solid,
                                  width: 1.5,
                                ),
                              ),
                            ),
                            onChanged: (val) {
                              setState(() {
                                Globals.latitude = val;
                              });
                            },
                          ),
                        ),
                      ],
                    ),
                    Divider(
                      thickness: 0,
                      height: 10,
                    ),
                    TextFormField(
                      initialValue: Globals.section,
                      decoration: InputDecoration(
                        labelText: "Section",
                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(5),
                          borderSide: BorderSide(
                            color: Colors.black,
                            style: BorderStyle.solid,
                            width: 1.5,
                          ),
                        ),
                      ),
                      onChanged: (val) {
                        setState(() {
                          Globals.section = val;
                        });
                      },
                    ),
                    Divider(
                      thickness: 0,
                      height: 10,
                    ),
                    TextFormField(
                      initialValue: Globals.division,
                      decoration: InputDecoration(
                        labelText: "Division",
                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(5),
                          borderSide: BorderSide(
                            color: Colors.black,
                            style: BorderStyle.solid,
                            width: 1.5,
                          ),
                        ),
                      ),
                      onChanged: (val) {
                        Globals.division = val;
                      },
                    ),
                    Divider(
                      thickness: 0,
                      height: 10,
                    ),
                    TextFormField(
                      initialValue: Globals.distance,
                      decoration: InputDecoration(
                        labelText: "Distance",
                        hintText: "In kilometers(km)",
                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(5),
                          borderSide: BorderSide(
                            color: Colors.black,
                            style: BorderStyle.solid,
                            width: 1.5,
                          ),
                        ),
                      ),
                      onChanged: (val) {
                        Globals.distance = val;
                      },
                    ),
                    Divider(
                      thickness: 0,
                      height: 10,
                    ),
                    DropdownButtonFormField<String>(
                      decoration: InputDecoration(
                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(5),
                          borderSide: BorderSide(
                            color: Colors.black,
                            style: BorderStyle.solid,
                            width: 1.5,
                          ),
                        ),
                      ),
                      hint: Text("Line"),
                      isExpanded: true,
                      items: <String>['Single', 'Up-Line', 'Down-Line']
                          .map((String value) {
                        return DropdownMenuItem<String>(
                          value: value,
                          child: Text(value),
                        );
                      }).toList(),
                      onChanged: (val) {
                        Globals.line = val;
                      },
                    ),
                    Divider(
                      thickness: 0,
                      height: 10,
                    ),
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Flexible(
                            child: Row(
                              children: [
                                Divider(
                                  indent: 15,
                                  endIndent: 5,
                                ),
                                Text("Start Time "),
                                TextButton(
                                  onPressed: () {
                                    showTimePicker(
                                            context: context,
                                            initialTime: sTime)
                                        .then((value) {
                                      if (value != null) {
                                        setState(() {
                                          sTime = value;
                                          Globals.stime = value.format(context);
                                        });
                                      }
                                    });
                                  },
                                  child: Globals.stime == null
                                      ? selectTime(sTime)
                                      : Text(" ${Globals.stime} "),
                                ),
                              ],
                            ),
                          ),
                          // Divider(
                          //   thickness: 0,
                          //   indent: 5,
                          // ),
                          Flexible(
                            child: Row(
                              children: [
                                Divider(
                                  indent: 10,
                                ),
                                Text("End Time "),
                                TextButton(
                                  onPressed: () {
                                    showTimePicker(
                                            context: context,
                                            initialTime: eTime)
                                        .then((value) {
                                      if (value != null) {
                                        setState(() {
                                          eTime = value;
                                          Globals.etime = value.format(context);
                                        });
                                      }
                                    });
                                  },
                                  child: Globals.etime == null
                                      ? selectTime(eTime)
                                      : Text(" ${Globals.etime} "),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Divider(
              height: 50,
            ),
          ],
        ),
      ),
    );
  }
}

这里用户可以在文本字段中输入,但是当他按下下一步时,他无法转到下一页。此外,当我在模拟器中 运行 它时,它工作得很好!。 是的,对每个页面进行截图很重要,因此我不能排除它。 有时它 returns Null,这可能是一个问题但我不知道如何处理它或下一步我应该做什么。 有什么建议请

这是我的构建 Gradle 文件

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.sweld"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

UpDate

我刚收到错误,是

[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: FileSystemException: Creation failed, path = 'storage/emulated/0/sweld' (OS Error: Operation not permitted, errno = 1)
E/flutter ( 7337): #0      _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:117:11)
E/flutter ( 7337): #1      _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter ( 7337): #2      _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter ( 7337): <asynchronous suspension>

所以请告诉我我是怎么做的??

尝试将 minSdkVersion 16 更改为 minSdkVersion 21

我解决了这个问题我获得了一些额外的权限。

MANAGE_EXTERNAL_STORAGE and INTERNET Permission

在 Android 清单文件中