#android #flutter #android-emulator #flutter-dependencies #android-11
Вопрос:
Вот Мой код
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,
),
],
),
),
);
}
}
Здесь пользователь может вводить данные в текстовые поля, но когда он нажимает «Далее», он не может перейти на следующую страницу. Более того, когда я запускаю его в эмуляторе, он работает совершенно нормально !.
И да, важно сделать скриншот каждой страницы, поэтому я не могу исключить это.
И иногда он возвращает значение 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"
}
Обновить
Я только что получил ошибку, это
[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>
Так что, пожалуйста, скажите мне, какое шоу я ДЕЛАЮ ??
Комментарии:
1. добавьте свой файл build.gradle, если это возможно.
2. С какой именно ошибкой вы сталкиваетесь при сборке для Android 11 ?
3. Моя следующая кнопка не работает (и они используют ее на реальном устройстве, поэтому у меня нет возможности узнать, что заставляет мое приложение не выполнять Навигатор)
4. Хорошо, в целевой и компилируемой версии sdk нет проблем.
5. Проверьте в своем файле манифеста Android, есть ли разрешение на доступ в Интернет или нет?
Ответ №1:
попробуйте изменить minSdkVersion 16
на minSdkVersion 21
Комментарии:
1. О, Дай мне Попробовать ! И есть ли какое-либо обоснованное объяснение, которое тоже будет полезно
2. Не повезло, братан, я все равно ничего не сделал, моя следующая кнопка не ведет меня на следующую страницу
Ответ №2:
Я решил эту проблему, получив Некоторые дополнительные Разрешения.
MANAGE_EXTERNAL_STORAGE and INTERNET Permission
в файле манифеста Android