aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.31k stars 242 forks source link

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value #1806

Closed ProgramSalamander closed 2 years ago

ProgramSalamander commented 2 years ago

Description

I'm new to amplify, and trying to access datastore using Amplify.Datastore.query (just follows the offiical doc).

try {
  final list = await Amplify.DataStore.query(XXX.classType);
} on DataStoreException catch (e) {
  print("error loading lessons: ${e.message}");
}

But once added this statement, the iOS app exited immediately :(.

The flutter console outputs:

Launching lib/main.dart on iPhone SE (3rd generation) in debug mode...
Running Xcode build...
Xcode build done.                                           21.7s
Debug service listening on ws://127.0.0.1:59339/bl3Huvf_7Rw=/ws
Syncing files to device iPhone SE (3rd generation)...
AmplifyPlugins/AWSDataStorePlugin+DataStoreBaseBehavior.swift:103: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
Lost connection to device.

Does anyone else meet this situation?

Categories

Steps to Reproduce

No response

Screenshots

No response

Platforms

Android Device/Emulator API Level

No response

Environment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.2, on macOS 12.4 21F79 darwin-arm, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.1.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.1.3)
[✓] VS Code (version 1.63.2)
[!] Proxy Configuration
    ! NO_PROXY is not set
[✓] Connected device (3 available)
[✓] HTTP Host Availability

Dependencies

Dart SDK 2.17.3
Flutter SDK 3.0.2

dependencies:
- amplify_api 0.6.0 [amplify_api_android amplify_api_ios amplify_core amplify_flutter aws_common collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.6.0 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_datastore 0.6.0 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_flutter 0.6.0 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- amplify_storage_s3 0.6.0 [amplify_storage_s3_android amplify_storage_s3_ios amplify_core aws_common meta flutter plugin_platform_interface]
- cupertino_icons 1.0.5
- dots_indicator 2.1.0 [flutter]
- email_validator 2.0.1
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_emoji 2.4.0 [characters http]
- flutter_screenutil 5.5.3+2 [flutter]
- flutter_svg 1.1.0 [flutter meta path_drawing vector_math xml]
- lpinyin 2.0.3
- path 1.8.1
- path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- provider 6.0.3 [collection flutter nested]
- quiver 3.1.0 [matcher]
- rxdart 0.27.4
- shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- sqflite 2.0.2+1 [flutter sqflite_common path]
- video_player 2.4.5 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web]

transitive dependencies:
- amplify_api_android 0.6.0 [flutter]
- amplify_api_ios 0.6.0 [amplify_core flutter]
- amplify_auth_cognito_android 0.6.0 [flutter]
- amplify_auth_cognito_ios 0.6.0 [amplify_core flutter]
- amplify_core 0.6.0 [aws_common collection flutter intl json_annotation meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.6.0 [amplify_core collection flutter meta]
- amplify_flutter_android 0.6.0 [flutter]
- amplify_flutter_ios 0.6.0 [amplify_core flutter]
- amplify_storage_s3_android 0.6.0 [flutter]
- amplify_storage_s3_ios 0.6.0 [flutter]
- async 2.8.2 [collection meta]
- aws_common 0.1.1 [async collection http meta stream_transform uuid]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.16.0
- crypto 3.0.2 [typed_data]
- csslib 0.17.2 [source_span]
- ffi 2.0.1
- file 6.1.2 [meta path]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- html 0.15.0 [csslib source_span]
- http 0.13.4 [async http_parser meta path]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- intl 0.17.0 [clock path]
- js 0.6.4
- json_annotation 4.5.0 [meta]
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.4
- meta 1.7.0
- nested 1.0.0 [flutter]
- path_drawing 1.0.0 [vector_math meta path_parsing flutter]
- path_parsing 1.0.0 [vector_math meta]
- path_provider_android 2.0.15 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.10 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.0 [ffi flutter path path_provider_platform_interface win32]
- petitparser 5.0.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- process 4.2.4 [file path platform]
- shared_preferences_android 2.0.12 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sky_engine 0.0.99
- source_span 1.8.2 [collection path term_glyph]
- sqflite_common 2.2.1+1 [synchronized path meta]
- stack_trace 1.10.0 [path]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- synchronized 3.0.0+2
- term_glyph 1.2.0
- typed_data 1.3.1 [collection]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2
- video_player_android 2.3.6 [flutter video_player_platform_interface]
- video_player_avfoundation 2.3.5 [flutter video_player_platform_interface]
- video_player_platform_interface 5.1.3 [flutter plugin_platform_interface]
- video_player_web 2.0.10 [flutter flutter_web_plugins video_player_platform_interface]
- win32 2.7.0 [ffi]
- xdg_directories 0.2.0+1 [meta path process]
- xml 6.1.0 [collection meta petitparser]

Device

iPhone SE - 3rd generation

OS

iOS 15.5

CLI Version

9.0.0

Additional Context

No response

fjnoyp commented 2 years ago

Hi @ProgramSalamander what docs did you follow? Did you follow the entire Getting Started section of DataStore?

https://docs.amplify.aws/lib/datastore/getting-started/q/platform/flutter/#sample-schema

ProgramSalamander commented 2 years ago

Hi @fjnoyp , in terms of creating schema, I did not follow the get started guide. I created the schema in Amplify Studio instead of using CLI, and used amplify pull to pull the schema to my project.

ProgramSalamander commented 2 years ago

Hi @fjnoyp , I tried to run the same app on another non-M1 macbook and this problem not exists. It feels like it's the M1 related issue. Hope this helps.

fjnoyp commented 2 years ago

Hi @ProgramSalamander I really appreciate the followup as that's very important to know!

I don't have an M1 macbook to reproduce but I'll check internally to see what we can do.

salihgueler commented 2 years ago

Hello @ProgramSalamander I tried to reproduce this error on an M1 macbook with your settings and I could not reproduce it. Can you try to create a new project and do a fresh setup, maybe a problem occurred during the setup. cc:// @fjnoyp

ProgramSalamander commented 2 years ago

Hi @salihgueler @fjnoyp, I just updated to version 0.6.1, and now the problem has gone. Maybe @salihgueler is right, my somewhere-messed project files could cause the crash. Anyway, thank you all for your efforts :)

abdallahshaban557 commented 2 years ago

Thank you for getting back to us, @ProgramSalamander!