Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datastore configuration issue #5116

Closed
2 of 14 tasks
Sushil787 opened this issue Jul 5, 2024 · 13 comments
Closed
2 of 14 tasks

Datastore configuration issue #5116

Sushil787 opened this issue Jul 5, 2024 · 13 comments
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced datastore Issues related to the DataStore Category pending-maintainer-response Pending response from a maintainer of this repository

Comments

@Sushil787
Copy link

Sushil787 commented Jul 5, 2024

Description

DatasStore configuration issue :
AWS Amplify with flutter :
I'm facing an issue while configuring Amplify DataStore in my Flutter app. The error I'm encountering is:
It seems like there might be an issue with the DataStore configuration or possibly with the plugins. Has anyone else faced a similar issue? Any insights or solutions would be greatly appreciated!
API,AUTH is configuring with no issue .
PS: I have followed as documentation and did researched too .
code snippets are provided in snapshot .
Unhandled Exception: type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast this is from package amplify core and datastore as exception is expecting map of exception value but got null.
if (e.code == 'AmplifyException') {
throw AmplifyException.fromMap(
Map<String, String>.from(e.details as Map),
);
But, with no exception message !!
}

here is my generated model provider :
/*

  • Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  • Licensed under the Apache License, Version 2.0 (the "License").
  • You may not use this file except in compliance with the License.
  • A copy of the License is located at
  • http://aws.amazon.com/apache2.0
  • or in the "license" file accompanying this file. This file is distributed
  • on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  • express or implied. See the License for the specific language governing
  • permissions and limitations under the License.
    */

// NOTE: This file is generated and may not follow lint rules defined in your app
// Generated files can be excluded from analysis in analysis_options.yaml
// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis

// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously

import 'package:amplify_core/amplify_core.dart' as amplify_core;
import 'Post.dart';
import 'User.dart';

export 'Post.dart';
export 'User.dart';

class ModelProvider implements amplify_core.ModelProviderInterface {
  @override
  String version = "9928aa2b60cc04806c3745869a03dcff";
  @override
  List<amplify_core.ModelSchema> modelSchemas = [Post.schema, User.schema];
  @override
  List<amplify_core.ModelSchema> customTypeSchemas = [];
  static final ModelProvider _instance = ModelProvider();

  static ModelProvider get instance => _instance;
  
  amplify_core.ModelType getModelTypeByModelName(String modelName) {
    switch(modelName) {
      case "Post":
        return Post.classType;
      case "User":
        return User.classType;
      default:
        throw Exception("Failed to find model in model provider for model name: " + modelName);
    }
  }
}


class ModelFieldValue<T> {
  const ModelFieldValue.value(this.value);

  final T value;
}

package used:

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.6
  aws_amplify_api: ^2.0.0
  amplify_core: ^2.2.0
  amplify_auth_cognito: ^2.2.0
  connectivity_plus: ^6.0.3
  injectable: ^2.4.2
  go_router: ^14.2.0
  uuid: ^3.0.7
  animated_text_kit: ^4.2.2
  cached_network_image: ^3.3.1
  google_fonts: ^4.0.4
  shared_preferences: ^2.2.3
  flutter_bloc: ^8.1.6
  image_picker: ^1.1.2
  amplify_api: ^2.2.0
  amplify_datastore: ^2.2.0
  amplify_storage_s3: ^2.2.0
  amplify_flutter: ^2.2.0
  intl: ^0.18.1
  amplify_authenticator: 
    path: './amplify_authenticator'
dev_dependencies:
  flutter_test:

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

import 'dart:developer';

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_storage_s3/amplify_storage_s3.dart';
import 'package:flutter/material.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_datastore/amplify_datastore.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:witpage/core/di/di_setup.dart';
import 'package:witpage/core/routes/app_router.dart';
import 'package:witpage/core/theme/app_theme.dart';
import 'package:witpage/feature/user/presentation/cubit/signin/auth_cubit.dart';

import 'amplifyconfiguration.dart';
import 'models/ModelProvider.dart';

Future<void> _configureAmplify() async {
  final datastorePlugin = AmplifyDataStore(
    modelProvider: ModelProvider.instance,
  );

  try {
    await Amplify.addPlugins([
      AmplifyAuthCognito(),
      datastorePlugin,
      AmplifyAPI(
          options: APIPluginOptions(modelProvider: ModelProvider.instance)),
      AmplifyStorageS3(),
    ]);

    if (!Amplify.isConfigured) {
      await Amplify.configure(amplifyconfig);
    }
  } catch (e) {
    log('Error configuring Amplify: $e');
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await _configureAmplify();
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  


  @override
  Widget build(BuildContext context) {
    return 
      child: Authenticator(
        child: MaterialApp.router(
          debugShowCheckedModeBanner: false,
          title: '',
          theme: AppTheme.lightThemeData,
          themeMode: ThemeMode.light,
          home:MyPage()
        ),
      );
  }
}

Screenshots

image image

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.19.6

Amplify Flutter Version

2.2.0

Deployment Method

Amplify CLI

Schema

Here is my graphql model:
type User @model @auth(rules: [{allow: public}]) {
  id: ID!
  uname: String
  email: AWSEmail
  profile_image: String
  Posts: [Post] @hasMany(indexName: "byUser", fields: ["id"])
}

type Post @model @auth(rules: [{allow: public}]) {
  id: ID!
  title: String
  body: String
  date_time: AWSDateTime
  userID: ID! @index(name: "byUser")
}
@NikaHsn
Copy link
Member

NikaHsn commented Jul 5, 2024

@Sushil787 sorry that you are facing this issue, Can you please share your amplifyconfiguration.dart with any sensitive info removed? Also what version of Amplify CLI do you use?

@NikaHsn NikaHsn added datastore Issues related to the DataStore Category pending-community-response Pending response from the issue opener or other community members pending-triage This issue is in the backlog of issues to triage labels Jul 5, 2024
@Sushil787
Copy link
Author

@NikaHsn
amplify --version
12.12.4

This is the amplifyConfiguration.dart
const amplifyconfig = '''{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"api": {
"plugins": {
"awsAPIPlugin": {
"witpage": {
"endpointType": "GraphQL",
"endpoint": "https://dummy.dummy-api.us-west-1.amazonaws.com/graphql",
"region": "us-west-1",
"authorizationType": "API_KEY",
"apiKey": "da2-dummy"
}
}
}
},
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"AppSync": {
"Default": {
"ApiUrl": "https://dummy.appsync-api.us-west-1.amazonaws.com/graphql",
"Region": "us-west-1",
"AuthMode": "API_KEY",
"ApiKey": "da2-dummy",
"ClientDatabasePrefix": "witpage_API_KEY"
},
"witpage_AWS_IAM": {
"ApiUrl": "https://dymmy.appsync-api.us-west-1.amazonaws.com/graphql",
"Region": "us-west-1",
"AuthMode": "AWS_IAM",
"ClientDatabasePrefix": "witpage_AWS_IAM"
}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "us-west-1:9e975edc-6e03-dummy-a987-dymmy",
"Region": "us-west-1"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "us-west-duymmy",
"AppClientId": "test",
"Region": "us-west-1"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": [
"REQUIRES_LOWERCASE",
"REQUIRES_NUMBERS",
"REQUIRES_UPPERCASE"
]
},
"signupAttributes": [],
"socialProviders": [],
"usernameAttributes": [
"EMAIL"
],
"verificationMechanisms": [
"EMAIL"
]
}
},
"S3TransferUtility": {
"Default": {
"Bucket": "bucket-id",
"Region": "us-west-1"
}
}
}
}
},
"storage": {
"plugins": {
"awsS3StoragePlugin": {
"bucket": "bucket-id,
"region": "us-west-1",
"defaultAccessLevel": "guest"
}
}
}
}''';

@NikaHsn
Copy link
Member

NikaHsn commented Jul 5, 2024

thank @Sushil787. we will look into this and get back to you with any updates.

@NikaHsn
Copy link
Member

NikaHsn commented Jul 5, 2024

@Sushil787, I used the amplifyConfiguration.dart you shared but couldn't replicate the problem with our Amplify DataStore example app. However, I stumbled upon another configuration error related to JSON formatting. Specifically, the "bucket-id value within the "awsS3StoragePlugin" object was missing a closing double quote ("). After correcting this, I managed to configure Amplify correctly.

below is the ConfigurationError I got when using theamplifyConfiguration.dart you shared. could you please verify if you get the same ConfigurationError using the shared amplifyConfiguration.dart?

ConfigurationError {
 "message": "The provided configuration is not a valid json. Check underlyingException.",
 "recoverySuggestion": "Inspect your amplify_outputs.dart or amplifyconfiguration.dart and ensure that the string is proper json", 
"underlyingException": "FormatException: Control character in string (at line 98, character 33)\n \"bucket\":\"bucket-id,\n                                ^\n"

@jamontesg
Copy link

jamontesg commented Jul 6, 2024

Hi @NikaHsn , I have a similar error:

Background concurrent copying GC freed 75929(3681KB) AllocSpace objects, 3(60KB) LOS objects, 49% free, 4417KB/8834KB, paused 2.934ms,14us total 158.244ms I/amplify:flutter:datastore( 8633): Added Auth plugin I/amplify:flutter:datastore( 8633): Added API plugin E/flutter ( 8633): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast E/flutter ( 8633): #0 AmplifyDataStore.configure (package:amplify_datastore/amplify_datastore.dart:141:46) E/flutter ( 8633): <asynchronous suspension>

IOS doesn't have this error, works fine.

This error only appears on ANDROID (emulator PHONE API 34).

this error happened when use with this packages :

amplify_analytics_pinpoint: 2.2.0
amplify_api: 2.2.0
amplify_api_dart: 0.5.2
amplify_auth_cognito: 2.2.0
amplify_authenticator: 2.1.0
amplify_core: 2.2.0
amplify_datastore: 2.2.0
amplify_datastore_plugin_interface: 2.2.0
amplify_flutter: 2.2.0
amplify_storage_s3: 2.2.0

but using previous versions, this error don't appears:

amplify_analytics_pinpoint: 2.1.0
amplify_api: 2.1.0
amplify_api_dart: 0.5.1
amplify_auth_cognito: 2.1.0
amplify_authenticator: 2.0.1
amplify_core: 2.1.0
amplify_datastore: 2.1.0
amplify_datastore_plugin_interface: 2.1.0
amplify_flutter: 2.1.0
amplify_storage_s3: 2.1.0

============================================

[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale es-CO)
• Flutter version 3.22.2 on channel stable at /Users/xontes/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 761747bfc5 (4 weeks ago), 2024-06-05 22:15:13 +0200
• Engine revision edd8546116
• Dart version 3.4.3
• DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/xontes/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15F31d
• CocoaPods version 1.15.2

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.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 17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.91.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.92.0

[✓] Connected device (4 available)
• sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 14 (API 34) (emulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.5 23F79 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.127

[✓] Network resources
• All expected network resources are available.

Kind Regards

amplifyconfiguration.txt

@Sushil787
Copy link
Author

Sushil787 commented Jul 6, 2024

related @NikaHsn
I may have missed a quote that while removing secrets, I think thats not the issue .
Can you share the configuration and which android api level are you working on !!
which version of amplify are you using and flutter packages and their versions ?

@Sushil787
Copy link
Author

Sushil787 commented Jul 6, 2024

@NikaHsn i also recently tested for IOS and it's working fine but for android it's not working !!
Did you configured Datastore only or all above four at once?
All four configuration may cause issue !!

@Williamjr23
Copy link

I'm not very experienced but could it be a problem with the latest version of Amplify cli?

@khatruong2009 khatruong2009 added bug Something is not working; the issue has reproducible steps and has been reproduced and removed pending-community-response Pending response from the issue opener or other community members pending-triage This issue is in the backlog of issues to triage labels Jul 10, 2024
@khatruong2009
Copy link
Member

Hi @Sushil787, @jamontesg, @Williamjr23, I was able to reproduce the issue and am working to determine the root cause now.

@khatruong2009
Copy link
Member

Hi @Sushil787, @jamontesg, @Williamjr23, the fix for this has been released. Please upgrade your amplify-datastore version to 2.2.1. I'm going to close this issue now, but please feel free to let us know if you have another issue that pops up or if this issue resurfaces.

@timonchev
Copy link

in 2.4.2 same error

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Oct 23, 2024
@minganp
Copy link

minganp commented Nov 19, 2024

the same issue. in android, after I pressed the 'return' button on the phone and re-launch it, this will happend. before I run Amplify.configure(amplifyconfig), I check print("before config amplify: ${Amplify.isConfigured}"); this is false, but when the Amplify.configure is running , I can see the printed out: E/amplify:flutter:datastore( 6620): Amplify has already been configured.
E/amplify:flutter:datastore( 6620): Amplify has already been configured.

@minganp
Copy link

minganp commented Nov 19, 2024

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast
E/flutter ( 6620): #0 AmplifyDataStore.configure (package:amplify_datastore/amplify_datastore.dart:141:46)
E/flutter ( 6620):
E/flutter ( 6620): #1 Future.wait. (dart:async/future.dart:534:21)
E/flutter ( 6620):
E/flutter ( 6620): #2 AmplifyClass._configurePlugins (package:amplify_core/src/amplify_class.dart:199:7)
E/flutter ( 6620):
E/flutter ( 6620): #3 AmplifyClass.configure (package:amplify_core/src/amplify_class.dart:118:7)
E/flutter ( 6620): . amplify_datastore: 2.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced datastore Issues related to the DataStore Category pending-maintainer-response Pending response from a maintainer of this repository
Projects
None yet
Development

No branches or pull requests

7 participants