flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.24k stars 27.1k forks source link

image_picker performance issue on Samsung Devices #72680

Closed Waheguru-Anurag closed 2 months ago

Waheguru-Anurag commented 3 years ago

Recently I created an app using the image_picker plugin but I found that the there was a time delay in Image being displayed in case of my physical device. I asked some of my friends to test this up and we concluded that the issue is mainly with samsung devices. After clicking the image it generally takes 4-5 sec for the image to get displayed on the screen.

Code

Code ``` import 'dart:io'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State { File _image; final picker = ImagePicker(); Future getImage() async { final pickedFile = await picker.getImage(source: ImageSource.camera); setState(() { if (pickedFile != null) { _image = File(pickedFile.path); } else { print('No image selected.'); } }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Image Picker Example'), ), body: Center( child: _image == null ? Text('No image selected.') : Image.file(_image), ), floatingActionButton: FloatingActionButton( onPressed: getImage, tooltip: 'Pick Image', child: Icon(Icons.add_a_photo), ), ); } } ```
Logs ``` I/Choreographer( 7032): Skipped 66 frames! The application may be doing too much work on its main thread. D/ViewRootImpl@4ec78c7[MainActivity]( 7032): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)0 dur=42 res=0x1 s={true 526766731264} ch=false D/ViewRootImpl@4ec78c7[MainActivity]( 7032): MSG_WINDOW_FOCUS_CHANGED 1 1 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 V/InputMethodManager( 7032): Starting input: tba=com.example.flutter_app ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false D/InputMethodManager( 7032): startInputInner - Id : 0 I/InputMethodManager( 7032): startInputInner - mService.startInputOrWindowGainedFocus D/ViewRootImpl@4ec78c7[MainActivity]( 7032): MSG_RESIZED: frame=(0,0,1080,2340) ci=(0,83,0,126) vi=(0,83,0,126) or=1 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 V/InputMethodManager( 7032): Starting input: tba=com.example.flutter_app ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false D/InputMethodManager( 7032): startInputInner - Id : 0 D/ViewRootImpl@4ec78c7[MainActivity]( 7032): MSG_WINDOW_FOCUS_CHANGED 0 1 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 D/ViewRootImpl@4ec78c7[MainActivity]( 7032): MSG_WINDOW_FOCUS_CHANGED 1 1 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 D/ViewRootImpl@4ec78c7[MainActivity]( 7032): MSG_WINDOW_FOCUS_CHANGED 0 1 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 D/ViewRootImpl@4ec78c7[MainActivity]( 7032): MSG_WINDOW_FOCUS_CHANGED 1 1 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 D/ViewRootImpl@4ec78c7[MainActivity]( 7032): ViewPostIme pointer 0 D/ViewRootImpl@4ec78c7[MainActivity]( 7032): ViewPostIme pointer 1 D/ViewRootImpl@4ec78c7[MainActivity]( 7032): MSG_WINDOW_FOCUS_CHANGED 0 1 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 D/InputTransport( 7032): Input channel destroyed: 'ClientS', fd=97 D/SurfaceView( 7032): onWindowVisibilityChanged(8) false io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} of ViewRootImpl@4ec78c7[MainActivity] D/SurfaceView( 7032): surfaceDestroyed callback.size 1 #2 io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} W/libEGL ( 7032): EGLNativeWindowType 0x7aa5be9010 disconnect failed D/SurfaceView( 7032): remove() io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} Surface(name=SurfaceView - com.example.flutter_app/com.example.flutter_app.MainActivity@56f561d@0)/@0x93a32db W/libEGL ( 7032): EGLNativeWindowType 0x7b2a01b810 disconnect failed D/ViewRootImpl@4ec78c7[MainActivity]( 7032): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)8 dur=21 res=0x5 s={false 0} ch=true D/ViewRootImpl@4ec78c7[MainActivity]( 7032): stopped(true) old=false D/SurfaceView( 7032): windowStopped(true) false io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} of ViewRootImpl@4ec78c7[MainActivity] D/SurfaceView( 7032): onWindowVisibilityChanged(4) false io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} of ViewRootImpl@4ec78c7[MainActivity] D/ViewRootImpl@4ec78c7[MainActivity]( 7032): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)4 dur=13 res=0x1 s={false 0} ch=false D/ViewRootImpl@4ec78c7[MainActivity]( 7032): stopped(false) old=true D/SurfaceView( 7032): windowStopped(false) false io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} of ViewRootImpl@4ec78c7[MainActivity] D/SurfaceView( 7032): onWindowVisibilityChanged(0) true io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} of ViewRootImpl@4ec78c7[MainActivity] D/ViewRootImpl@4ec78c7[MainActivity]( 7032): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)0 dur=12 res=0x7 s={true 526766735360} ch=true D/OpenGLRenderer( 7032): createReliableSurface : 0x7b2a01b800, 0x7aa5be8000 D/mali_winsys( 7032): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000 D/SurfaceView( 7032): surfaceCreated 1 #8 io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} D/mali_winsys( 7032): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000 D/SurfaceView( 7032): surfaceChanged (1080,2214) 1 #8 io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} D/ViewRootImpl@4ec78c7[MainActivity]( 7032): stopped(false) old=false D/ViewRootImpl@4ec78c7[MainActivity]( 7032): MSG_WINDOW_FOCUS_CHANGED 1 1 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 V/InputMethodManager( 7032): Starting input: tba=com.example.flutter_app ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false D/InputMethodManager( 7032): startInputInner - Id : 0 I/InputMethodManager( 7032): startInputInner - mService.startInputOrWindowGainedFocus D/ViewRootImpl@4ec78c7[MainActivity]( 7032): ViewPostIme key 0 D/ViewRootImpl@4ec78c7[MainActivity]( 7032): ViewPostIme key 1 D/ViewRootImpl@4ec78c7[MainActivity]( 7032): MSG_WINDOW_FOCUS_CHANGED 0 1 D/InputMethodManager( 7032): prepareNavigationBarInfo() DecorView@d39f65[MainActivity] D/InputMethodManager( 7032): getNavigationBarColor() -855310 D/InputTransport( 7032): Input channel destroyed: 'ClientS', fd=92 D/SurfaceView( 7032): onWindowVisibilityChanged(8) false io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} of ViewRootImpl@4ec78c7[MainActivity] D/SurfaceView( 7032): surfaceDestroyed callback.size 1 #2 io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} W/libEGL ( 7032): EGLNativeWindowType 0x7aa5c92010 disconnect failed D/SurfaceView( 7032): remove() io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} Surface(name=SurfaceView - com.example.flutter_app/com.example.flutter_app.MainActivity@56f561d@1)/@0xf281790 W/libEGL ( 7032): EGLNativeWindowType 0x7b2a01b810 disconnect failed D/ViewRootImpl@4ec78c7[MainActivity]( 7032): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)8 dur=13 res=0x5 s={false 0} ch=true D/ViewRootImpl@4ec78c7[MainActivity]( 7032): stopped(true) old=false D/SurfaceView( 7032): windowStopped(true) false io.flutter.embedding.android.FlutterSurfaceView{56f561d V.E...... ........ 0,0-1080,2214} of ViewRootImpl@4ec78c7[MainActivity] D/ViewRootImpl@4ec78c7[MainActivity]( 7032): dispatchDetachedFromWindow D/InputTransport( 7032): Input channel destroyed: '92cf0bc', fd=85 F/OIC_SRM_DOXM(10687): UpdatePersistentStorage failed! ```
flutter doctor ``` [✓] Flutter (Channel stable, 1.22.5, on Linux, locale en_IN) • Flutter version 1.22.5 at /home/anurag/development/flutter • Framework revision 7891006299 (10 days ago), 2020-12-10 11:54:40 -0800 • Engine revision ae90085a84 • Dart version 2.10.4 [!] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /home/anurag/Android/Sdk • Platform android-30, build-tools 30.0.2 • ANDROID_HOME = /home/anurag/Android/Sdk • Java binary at: /usr/bin/java • Java version OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04) ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/linux#android-setup for more details. [!] Android Studio • Android Studio at /home/anurag/AndroidStudio ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. ✗ android-studio-dir = /home/anurag/AndroidStudio ✗ Unable to find bundled Java version. • Try updating or re-installing Android Studio. • Consider removing your android-studio-dir setting by running: flutter config --android-studio-dir= [✓] Connected device (2 available) • SM A305F (mobile) • RZ8M60G6H4J • android-arm64 • Android 10 (API 29) • Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator) ! Doctor found issues in 2 categories. ```
pedromassangocode commented 3 years ago

Saw no issues on Samsung s10. It takes around 2 seconds to show the image but this is expected considering that Flutter has to get the image data from the host platform and this take time.

https://user-images.githubusercontent.com/67424416/102778867-9a206580-4393-11eb-9d6d-0f389e1fb210.mp4

flutter doctor -v ``` [✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.4 19E2269 darwin-x64, locale en-IN) • Flutter version 1.22.5 at /Users/dhs/documents/Fluttersdk/flutter • Framework revision 7891006299 (11 days ago), 2020-12-10 11:54:40 -0800 • Engine revision ae90085a84 • Dart version 2.10.4 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0) • Android SDK at /Users/dhs/Library/Android/sdk • Platform android-30, build-tools 30.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 12.0.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.0.1, Build version 12A7300 • CocoaPods version 1.9.3 [✓] Android Studio (version 4.0) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 46.0.2 • Dart plugin version 193.7361 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] VS Code (version 1.51.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.16.0 [✓] Connected device (1 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 10 (API 29) • No issues found! ```
Waheguru-Anurag commented 3 years ago

When we display a set of other widgets along with the image in a column, the delay in image loading provide a bad user experience.

https://user-images.githubusercontent.com/54813606/102783872-973c6980-43c1-11eb-93fb-14b0369e2060.mp4

huycozy commented 3 months ago

@Waheguru-Anurag I re-checked this issue using Galaxy Tab A7 Lite but I also see it took only around 2 seconds to show the captured picture since pressing OK button on the native camera output screen.

I'm using the latest package version image_picker: ^1.1.1. This could only happen on a specific Samsung device model. What is your device model? Could you recheck this with the latest package version?

HarshNarayanJha commented 3 months ago

Happens to me also on Samsung A14 5G. Around 1.5 seconds for the Ok/Cancel to show up and another 1.5 - 2 seconds for the image to really show up in the widget

huycozy commented 3 months ago

@HarshNarayanJha Could you please share the package version you are using, along with a recorded video that would be useful?

HarshNarayanJha commented 3 months ago

I am using the latest version image_picker ^1.1.1. Here is the video:

https://github.com/flutter/flutter/assets/50262541/c84a8b14-8fdd-448e-ad6c-aca79ba079a6

huycozy commented 3 months ago

@HarshNarayanJha Thanks for providing a video. It seems to take only 1-1.5 sec to get displayed on the screen, it's faster than the demo at https://github.com/flutter/flutter/issues/72680#issuecomment-74898450. It would be more helpful if you could compare it with other devices.

HarshNarayanJha commented 3 months ago

Sure! I can't get the video for this device. But on Samsung Galaxy M20 it is almost ~2 seconds on each step. (image click -> Cancel/OK button ; main activity -> image appeared ). I am planning to get my app to a few testers this week, and I can provide statistics for even more devices by asking them.

HarshNarayanJha commented 3 months ago

Also, missed to add points to the video.

How can I prevent this crashing, as this is happening more than often. Comparable act in other apps such as WhatsApp, which also open camera on Main Activity, almost never crash, rather they open up a brand new activity (of sending the captured image) and return to the Main Activity without any hiccups

huycozy commented 3 months ago

@HarshNarayanJha Crashing issue should be separated from this issue for better tracking. So if there is a crash, please file another issue for it (it would be more helpful if you can get the stack trace when it happens)

github-actions[bot] commented 2 months ago

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.

github-actions[bot] commented 2 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.