Repository: aws-amplify/amplify-flutter

Issue #2652: AmplifyHub  returns NetworkStatusEvent.active = false for HubChannel.DataStore unintentionally!
Created: 2023-02-16T21:57:24Z
Description
Hi there @amplify-flutter team , we are facing a seriour bug from last couple of days , Its related to datastore the stream AmplifyHUb.listen() for HubChannel.DataStore return the NetworkStatusEvent.active=false and the datastore in unable to communicate with the cloud even the network is stable and everything from code base is according to the documentation , The issue arrive sometime while sometime its vanished , can you guys please help us out of this trap since we have a deadline and we have tested all these things each and every time but this unknown issue effecting us . So need any suggested work around to solve this like it was before
Categories

 Analytics
 API (REST)
 API (GraphQL)
 Auth
 Authenticator
 DataStore
 Storage

Steps to Reproduce
The issue was first time arrived on emulator so we shifting our unit testing and debuggin to real device but now its come on real device as well and once it trigger we are unable to do any kind of query with our datastore after our login process.
All we doing is fetching user data from datastore which is already save on table And at the very begining of app we are using the listener as suggested in datastore even docs of aws amplify here it is
initDataStoreEventHandler() async {
    print('@AuthViewModel');
    datastoreHubSubscription =
        Amplify.Hub.listen([HubChannel.DataStore], (hubEvent) {
      print("hubevent2 is=== ${hubEvent.eventName}");
      if (hubEvent.eventName == 'networkStatus') {
        final status = hubEvent.payload as NetworkStatusEvent?;
        networkIsUp = status?.active ?? false;
        setState(ViewState.idle);
        if (!networkIsUp) {
          Get.dialog(RequestFailedDialog(
              title: "Network Error",
              errorMessage:
                  "Please Check your network as the datastore cant connect to cloud without a stable network",
              onPressed: () {
                Get.back();
              }));
        }
      }
      // handleDatastoreEvents(hubEvent);
    });
  }

It was working recently pretty awesome out of the box and the status is going to be false only on when we turn off the network but now the status is becoming false even the network is stable .
Wanna to provide some more detail why we are using the above listener check ===> Its is because while saving or querying to db we were facing the issue of Appsync since appsync failed to load the local data to cloud each time so we implemented this above datastore stream event handler where we can now see in logs when the datastore is ready for querying but after couple of days now instead of ready event its sometime stuck on networkstatus. hubevent2 is=== networkStatus
Screenshots

Platforms

 iOS
 Android
 Web
 macOS
 Windows
 Linux

Flutter Version
3.3.8
Amplify Flutter Version
0.6.12
Deployment Method
Amplify CLI
Schema
type NotificationSettings @model @auth(rules: [{allow: public}]) {
  id: ID!
  stashMilestone: Boolean
  moneyReceived: Boolean
  productUpdate: Boolean
  monthlyNewsletter: Boolean
}

type UserBenefciary @model @auth(rules: [{allow: public}]) {
  id: ID!
  pmtRefNo: String
  name: String
  phoneNumber: String
  email: String
  senderId: String
  lastAmountTransfer: Float
  createdAt: AWSDateTime
}

enum AwsAddressType {
  PHYSICAL
  MAILING
}

type AwsAddress @model @auth(rules: [{allow: public}]) {
  id: ID!
  suiteNumber: String
  zipCode: String
  city: String
  state: String
  address: String
  type: AwsAddressType
}

type USER @model @auth(rules: [{allow: public}]) {
  id: ID!
  name: String!
  email: String
  password: String
  mobilePasscode: String
  userAffiliation: String!
  isTermsSelected: Boolean
  pmtRefNo: String
  phoneNumber: String
  physicalAddressId: String
  mailingAddressId: String
  plaidAccessToken: String
  isBlocked: Boolean
  reasonForBlock: String
  truvLinkId: String
  deviceToken: String
  createdAt: AWSDateTime
  profileImage: String
  dateOfBirth: AWSDate
  notificationSettingId: String
  ssn: String
}

type Affilation @model @auth(rules: [{allow: public}]) {
  id: ID!
  name: String!
}

Duplicate issue #2680: DataStore  publishing wrong state notifications onto Amplify's Hub. NetworkStatusEvent.active = false even with stable network
Created: 2023-02-18T19:12:51Z
Description
Hello there amplify team the HubChannel.datastore is returning some strange data even the network is stable but still the networkstatusEvent.active is false due to which i am unable to fetch any data from datastore , and when this happens then appsync is also not going to work since the connection between datastore local and and cloud is unable to established everything is implemented according to docs , so can you please help me by suggesting some workaround thats functional.
Categories

 Analytics
 API (REST)
 API (GraphQL)
 Auth
 Authenticator
 DataStore
 Storage

Steps to Reproduce
No response
Screenshots
No response
Platforms

 iOS
 Android
 Web
 macOS
 Windows
 Linux

Flutter Version
3.3.8
Amplify Flutter Version
0.6.12
Deployment Method
Amplify CLI
Schema
No response

Closing comment (2023-02-22T17:05:39Z): Closing as a duplicate of #2652