I'm new to Flutter and would love some help with an error.
While using the image_picker package, I noticed that I'm getting a value of null returned when I try to select an image from ios photo gallery.
(Specifically, [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_storage/object-not-found] No object exists at the desired reference.)
I read the package documentation where it says this is a known issue and to try it on a real device. I tried it on my real device an only got the desired result once. Can someone please shed some light on this? Below, I have provided the necessary code and a look and my flutter doctor. Thanks in advance!
P.S. To be clear, I am trying to test this on my physical ios device(iPhone 14 Pro Max), as I am aware of the issue with the ios Simulator and the image_picker package.
Please let me know if I need to provide more information to resolve this issue!
String? photoUrl = " ";
File? image;
Future pickImage() async {
try {
final image = await ImagePicker()
.pickImage(source: ImageSource.gallery, requestFullMetadata: false);
if (image == null) return;
Reference ref = FirebaseStorage.instance.ref().child("profilepic.jpg");
await ref.putFile(File(image.path));
await ref.getDownloadURL().then((value) {print(value); setState(() {
photoUrl = value;
});});
} on PlatformException catch (e) {
debugPrint('Failed to pick image: $e');
}
}
profilePic() {
final Size size = MediaQuery.of(context).size;
return SizedBox(
height: size.height * 0.185,
width: double.infinity,
child: Column(children: [
const Spacer(),
photoUrl != null
?
GestureDetector(
onTap: () {
pickImage();
},
child: Container(
height: 120,
width: 160,
decoration: const BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
child: const Icon(
Icons.person,
size: 50,
color: Colors.white,
),
),
):Image.network(photoUrl!),
],
),
);
}
[✓] Flutter (Channel stable, 3.7.0, on macOS 12.6.1 21G217 darwin-arm64, locale en-US)
• Flutter version 3.7.0 on channel stable at /Users/myronsp/Developer/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b06b8b2710 (9 days ago), 2023-01-23 16:55:55 -0800
• Engine revision b24591ed32
• Dart version 2.19.0
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/myronsp/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• ANDROID_HOME = /Users/myronsp/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
[✓] Connected device (5 available)
• sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator)
• Myron’s iPhone (mobile) • 00008120-00016D500A80C01E • ios • iOS 16.0.2 20A380
• iPhone 14 Pro Max (mobile) • B8ACBFEA-35E5-4D2C-810C-46100D17EE63 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.6.1 21G217 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119
hope you are included all the required steps for accessing gallery in android and iOS as mentioned here.
other chances are out dated packages in the flutter project.
please check the following link to rectify that link
If i am understanding correctly, below your spacer widget in your column children the condition should be photoUrl == null instead of photoUrl != null.
It would be good if you can share some findings.
Related
I am trying to use the following function in flutter:
Future<File> getFile(String fileName) async {
final appDir = await getTemporaryDirectory();
final appPath = appDir.path;
final fileOnDevice = File('$appPath/$fileName');
final rawAssetFile = await rootBundle.load(fileName);
final rawBytes = rawAssetFile.buffer.asUint8List();
await fileOnDevice.writeAsBytes(rawBytes, flush: true);
return fileOnDevice;
}
But somehow i keep getting this error, failed PathNotFoundException: Cannot open file, path = '/var/mobile/Containers/Data/Application/352527E9-XXXX-XXXX-XXXX-DCFXXXXXXXXX/Library/Caches/assets/
The function is called by final dataFile = await getFile('assets/sample.txt');
Does anyone know how to solve this? Any help is appreciated!
This is my flutter doctor -v
[✓] Flutter (Channel stable, 3.7.0, on macOS 13.1 22C65 darwin-arm64, locale en-SG)
• Flutter version 3.7.0 on channel stable at /Users/xaviertoh/Documents/Flutter/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b06b8b2710 (3 weeks ago), 2023-01-23 16:55:55 -0800
• Engine revision b24591ed32
• Dart version 2.19.0
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at /Users/xaviertoh/Library/Android/sdk
• Platform android-33, build-tools 33.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[✓] VS Code (version 1.75.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.58.0
[✓] Connected device (3 available)
• iPhone (mobile) • 00008020-000D05313C02002E • ios • iOS 13.5 17F75
• macOS (desktop) • macos • darwin-arm64 • macOS 13.1 22C65
darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 110.0.5481.77
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Thank you for reading!
Things i have tried:
I have confirmed that my file name is correct in the assets folder and i also tried running this code in various locations in the code such as in a widget and also in main() just to test it out.
I also tried running flutter in xcode and visual studio code.
Also tried to run the code in android emulator and also on iPhone physical device.
The /var/mobile/Containers/Data/Application/.../Library/Caches/assets/ directory must already exist. File.writeAsBytes won't automatically create parent directories for you.
You can do that step by first doing:
await fileOnDevice.parent.create(recursive: true);
We would like to use CameraController.startImageStream() instead of CameraController.takePicture() to get a return value equivalent to CameraController.takePicture(). We know that various answers have been documented for these but we have not yet succeeded with any of the methods.
We have implemented the following. We tried setting the imageFormatGroup during CameraController generation, but this did not improve things. We have to make these work on both Android and iOS. We want a way to run it faster. It can be written in Flutter or using C++ and ffi.
import 'package:image/image.dart' as imglib;
final cameras = await availableCameras();
final firstCamera = cameras.first;
cameraController = CameraController(
firstCamera,
ResolutionPreset.medium,
// imageFormatGroup: ImageFormatGroup.yuv420,
);
await cameraController!.initialize();
await cameraController!.startImageStream((CameraImage cameraImage) async {
cameraController!.stopImageStream();
Uint8List list = cameraImage.planes.first.bytes;
final width = cameraImage.width;
final height = cameraImage.height;
imglib.Image test = imglib.Image.fromBytes(width, height, list);
List<int> _imageBytes = imglib.encodeJpg(test);
Uint8List convert = Uint8List.fromList(_imageBytes);
File file = File.fromRawPath(convert);
XFile? result = XFile(file.path);
});
Index out of range occurred when we called encodeJpg(). How should we fix this?
fvm flutter doctor -v
[✓] Flutter (Channel stable, 3.3.6, on macOS 12.6 21G115 darwin-x64, locale en-JP)
• Flutter version 3.3.6 on channel stable at /Users/xxxxx/fvm/versions/stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 6928314d50 (3 weeks ago), 2022-10-25 16:34:41 -0400
• Engine revision 3ad69d7be3
• Dart version 2.18.2
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/xxxxx/src/android-sdks
• Platform android-33, build-tools 33.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 13F100
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] VS Code (version 1.73.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.52.0
[✓] Connected device (3 available)
• SHV43 (mobile) • XXXXXXXXXXXXXXX • android-arm64 • Android 10 (API 29)
• macOS (desktop) • macos • darwin-x64 • macOS 12.6 21G115 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.110
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
I assume your problem comes from mixing different image formats.
The camera stream in this line
Uint8List list = cameraImage.planes.first.bytes
returns an image that is encoded with YUV instead of the common RGB. So before further using this image, I would recommend converting it.
There are multiple sources already out there on how to do that conversion. Let me point you to this blog post and the following stackoverflow questions: 1 2.
You certainly can implement this conversion via ffi, but it is not strictly necessary.
In scrollable widget, when google map come to screen edges, its camera position slightly shifting. And it produces lagging
Is there an any way to prevent this behavior. Its like google_map trying to reposition its camera. I think this is like an undesired outcome. How could I keep stable the map while it is at screen edges
Sample code and flutter doctor outputs are below the example gif.
Code sample
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class DenemePage extends StatelessWidget {
const DenemePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(top: 200, bottom: 1500),
child: Container(
width: MediaQuery.of(context).size.width,
height: 400,
child: Stack(
alignment: Alignment.center,
children: [
GoogleMap(
initialCameraPosition:
const CameraPosition(target: LatLng(40, 29), zoom: 10),
),
Icon(Icons.radar_outlined)
],
),
),
),
);
}
}
Flutter Doctor
[✓] Flutter (Channel stable, 2.10.3, on macOS 12.4 21F79 darwin-x64, locale tr-TR)
• Flutter version 2.10.3 at /Volumes/HARDDISK/SDKs/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 7e9793dee1 (5 months ago), 2022-03-02 11:23:12 -0600
• Engine revision bd539267b4
• Dart version 2.16.1
• DevTools version 2.9.2
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Volumes/HARDDISK/SDKs/Android/sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.69.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.44.0
[✓] Connected device (2 available)
• iPhone 13 Pro (mobile) • BE0A3070-5A72-46F4-A649-6C7F17B9A731 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
I have created a solution.
Download the google_maps_flutter
Edit the code in google_maps_flutter-2.1.8/iOS/Classes/GoogleMapController.m from
_mapView.delegate = weakSelf;
_registrar = registrar;
to
_mapView.delegate = weakSelf;
_mapView.paddingAdjustmentBehavior = kGMSMapViewPaddingAdjustmentBehaviorNever;
_registrar = registrar;
Put this modified google_maps_flutter-2.1.8 folder into somewhere. Let say parentFolder/google_maps_flutter-2.1.8.
In pubspec.yaml file which flutter project you want to use this modified package.
google_maps_flutter:
path: parentFolder/google_maps_flutter-2.1.8
Also I have opened a issue about that on GitHub. More detailed info is at there.
i am a newbe at programming, i am very interested in flutter(dart).
Now i am facing my first big problem and i hope someone can help me out.
I would like use the flutter image picker pakage to get a image from my gallary or camera and show my users on the screen. So far so good and it works on emulator, also on my device but just if its connected to my pc, but if i build a release apk and send it to any device it doesent work. Watch at the videos.
Here it works:
https://streamable.com/3nj93j
Here the release apk Version
https://streamable.com/ba7eil
What i tried:
I have found few similar problams and i thounght it is a storage problem, i used:
android:requestLegacyExternalStorage="true"
but it doesent help, also i tried set the sdk from 30 to 28, nothing helps
Update: I build the app-debug.apk and send it to my device, it works fine.
I dont get it why the app-relase.apk ist not working???
Here my Methode:
Future getImage() async {
PickedFile pickedFile = await picker.getImage(source: ImageSource.camera);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
} else {
print('No image selected.');
}
});
}
I hope anyone have a idea
[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.18363.1316], locale de-AT)
• Flutter version 1.22.6 at C:\Flutter\flutter
• Framework revision 9b2d32b605 (3 weeks ago), 2021-01-22 14:36:39 -0800
• Engine revision 2f0af37152
• Dart version 2.10.5
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:/Users/acas1/AppData/Local/Android/Sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = C:/Users/acas1/AppData/Local/Android/Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin installed
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] Connected device (1 available)
• SM F916B (mobile) • R3CN80VJP2V • android-arm64 • Android 11 (API 30)
I have a different behaviour when I run my app on Chrome then when I run it on iOS. It happens when I get to this screen:
import 'dart:io';
import 'package:fixit_shop_flutter/fixit_shop_app/authentication_bloc/user_repository.dart';
import 'package:fixit_shop_flutter/fixit_shop_app/register/bloc/register_bloc.dart';
import 'package:fixit_shop_flutter/fixit_shop_app/register/register_form.dart';
import 'package:fixit_shop_flutter/localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class RegisterScreen extends StatelessWidget {
final UserRepository _userRepository;
RegisterScreen({Key key, #required UserRepository userRepository})
: assert(userRepository != null),
_userRepository = userRepository,
super(key: key);
#override
Widget build(BuildContext context) {
dynamic backButton =
Platform.isIOS ? CupertinoIcons.back : Icons.arrow_back;
return Stack(
children: [
Image.asset('assets/mainBg.png',
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover),
Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
centerTitle: true,
elevation: 0,
title: Text(
AppLocalizations.instance.text('RegisterScreenTitle'),
// textAlign: TextAlign.center,
style: TextStyle(
color: Colors.orange,
fontSize: 22,
fontWeight: FontWeight.w500,
letterSpacing: 1),
),
backgroundColor: Colors.transparent,
leading: IconButton(
icon: Icon(backButton),
color: Colors.redAccent,
onPressed: () {
Navigator.pop(context);
}),
),
body: BlocProvider<RegisterBloc>(
create: (context) => RegisterBloc(userRepository: _userRepository),
child: RegisterForm(),
),
),
],
);
}
}
If on iOS the screen loads normally, while when running the web version it throws the Another exception was thrown: Failed assertion: boolean expression must not be null error.
Do you now what could cause this different behaviour? I followed all the widgets that pass the userRepository along the tree and is all good..as in fact on iOS runs properly.
Here is my flutter doctor :
[✓] Flutter (Channel unknown, v1.12.13+hotfix.5, on Mac OS X 10.13.6 17G65, locale en-IT)
• Flutter version 1.12.13+hotfix.5 at /Users/vinnytwice/Developer/flutter
• Framework revision 27321ebbad (5 months ago), 2019-12-10 18:15:01 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/vinnytwice/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.2.1, Build version 10E1001
• CocoaPods version 1.8.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 44.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] Connected device (3 available)
• iPad Pro (10.5-inch) • 23C29147-A4F3-4B9F-8182-9C813D5A54AD • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-2 (simulator)
• Chrome • chrome • web-javascript • Google Chrome 81.0.4044.129
• Web Server • web-server • web-javascript • Flutter Tools
• No issues found!
Do you see anything to update? I'm on High Sierra so I think I can't go above Flutter version 1.12.13+hotfix.5. Also I see that the channel is unknown..could it have something to do with it ?
As always many thanks for your time and help.
Cheers.
found the reason.. it wasn't the assertion but the platform check I was doing on backButton, that only included iOS..I added the check for the web and it now works es expected. I'll leave the question up as might help others porting their apps to web.
dynamic backButton;
if (kIsWeb) {
backButton = Icons.arrow_back;
} else if (Platform.isIOS) {
backButton = CupertinoIcons.back;
} else {
backButton = Icons.arrow_back;
}