{"action":"closed","issue":{"url":"https://api.github.com/repos/flutter/flutter/issues/23368","repository_url":"https://api.github.com/repos/flutter/flutter","labels_url":"https://api.github.com/repos/flutter/flutter/issues/23368/labels{/name}","comments_url":"https://api.github.com/repos/flutter/flutter/issues/23368/comments","events_url":"https://api.github.com/repos/flutter/flutter/issues/23368/events","html_url":"https://github.com/flutter/flutter/issues/23368","id":372533542,"node_id":"MDU6SXNzdWUzNzI1MzM1NDI=","number":23368,"title":"StreamBuilder hangs when listening to Firestore snapshot","user":{"login":"dooboolab","id":27461460,"node_id":"MDQ6VXNlcjI3NDYxNDYw","avatar_url":"https://avatars0.githubusercontent.com/u/27461460?v=4","gravatar_id":"","url":"https://api.github.com/users/dooboolab","html_url":"https://github.com/dooboolab","followers_url":"https://api.github.com/users/dooboolab/followers","following_url":"https://api.github.com/users/dooboolab/following{/other_user}","gists_url":"https://api.github.com/users/dooboolab/gists{/gist_id}","starred_url":"https://api.github.com/users/dooboolab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dooboolab/subscriptions","organizations_url":"https://api.github.com/users/dooboolab/orgs","repos_url":"https://api.github.com/users/dooboolab/repos","events_url":"https://api.github.com/users/dooboolab/events{/privacy}","received_events_url":"https://api.github.com/users/dooboolab/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-10-22T14:00:18Z","updated_at":"2018-10-22T19:50:46Z","closed_at":"2018-10-22T19:50:46Z","author_association":"NONE","body":"## Steps to Reproduce\r\nI am trying to use the bloc pattern with firebase and having hard time since there is not good tutorial out there which uses `firebase` and `bloc pattern`.\r\n\r\nI've faced strange thing while doing this and worked hard to find out the problem but couldn't.\r\n\r\nI've created `UserBloc` and tried to set `UserModel` after listening to `Firestore snapshot`.\r\n```\r\nclass UserBloc extends Object {\r\n  final _user = StreamController<UserModel>.broadcast();\r\n  final _uid = StreamController<String>.broadcast();\r\n\r\n  Stream<UserModel> get user => _user.stream;\r\n  Stream<String> get uid => _uid.stream;\r\n\r\n  Function(UserModel) get setUser => _user.sink.add;\r\n  Function(String) get setUID => _uid.sink.add;\r\n\r\n  Stream<DocumentSnapshot> userStream;\r\n\r\n  UserBloc() {\r\n    uid.listen((uid) {\r\n      print('user : $uid');\r\n      if (uid != null) {\r\n        fromUID(uid);\r\n      }\r\n    });\r\n  }\r\n\r\n  fromUID(String uid) {\r\n    print('fromUID');\r\n    userStream = Firestore.instance.collection('users').document(uid).snapshots();\r\n\r\n   /// works ok when I delete below subscription\r\n    userStream.listen((data) {\r\n    });\r\n  }\r\n\r\n  dispose() {\r\n    _user.close();\r\n    _uid.close();\r\n  }\r\n}\r\n```\r\n\r\nThen I used the `StreamBuilder` inside my widget like below.\r\n```\r\n  StreamBuilder(\r\n    stream: userBloc.userStream,\r\n    builder: (context, snapshot) {\r\n      print(snapshot.connectionState);\r\n      print(snapshot.data);\r\n      return Text('testing');\r\n    },\r\n  );\r\n```\r\n\r\nThe problem is the `snapshot.connectionState` is always `waiting`. However, when I delete the subscription code which is ` userStream.listen((data) {`, I was able to get this working. All the example do the listen and set the data in the constructor of `bloc`. I have no idea why this is happening.\r\n\r\n## Logs\r\n\r\n```\r\n...\r\n[  +12 ms] [DEVICE LOG] 2018-10-22 22:58:48.521384+0900  localhost Runner[27014]: (Flutter) flutter: isHost: false\r\n[        ] flutter: isHost: false\r\n[  +46 ms] [DEVICE LOG] 2018-10-22 22:58:48.567490+0900  localhost Runner[27014]: (Flutter) flutter: ConnectionState.waiting\r\n[        ] [DEVICE LOG] 2018-10-22 22:58:48.567584+0900  localhost Runner[27014]: (Flutter) flutter: null\r\n[        ] flutter: ConnectionState.waiting\r\n[        ] flutter: null\r\n[  +69 ms] [DEVICE LOG] 2018-10-22 22:58:48.636881+0900  localhost Runner[27014]: (Flutter) flutter: userId: 9xqbCzwstrOI7MVXW7cLG2KMP0u1\r\n[        ] flutter: userId: 9xqbCzwstrOI7MVXW7cLG2KMP0u1\r\n[   +1 ms] [DEVICE LOG] 2018-10-22 22:58:48.638997+0900  localhost Runner[27014]: (Flutter) flutter: documents: 1\r\n[        ] [DEVICE LOG] 2018-10-22 22:58:48.639076+0900  localhost Runner[27014]: (Flutter) flutter: docChanges: 1\r\n[        ] flutter: documents: 1\r\n[        ] flutter: docChanges: 1\r\n[   +2 ms] [DEVICE LOG] 2018-10-22 22:58:48.641936+0900  localhost Runner[27014]: (Flutter) flutter: change\r\n[        ] [DEVICE LOG] {hostId: JtaSMOrZNlOlKQLPLCfDgWCglF93, guestId: 9xqbCzwstrOI7MVXW7cLG2KMP0u1, marketId: 9xqbCzwstrOI7MVXW7cLG2KMP0u1, title: My Market, lastMessage: test, updatedAt: 2018-10-10 10:29:24.710, createdAt: 2018-10-10 10:29:24.710}\r\n[        ] flutter: change\r\n[        ] {hostId: JtaSMOrZNlOlKQLPLCfDgWCglF93, guestId: 9xqbCzwstrOI7MVXW7cLG2KMP0u1, marketId: 9xqbCzwstrOI7MVXW7cLG2KMP0u1, title: My Market, lastMessage: test, updatedAt: 2018-10-10 10:29:24.710, createdAt: 2018-10-10 10:29:24.710}\r\n[        ] [DEVICE LOG] 2018-10-22 22:58:48.643003+0900  localhost Runner[27014]: (Flutter) flutter: init\r\n[        ] flutter: init\r\n[  +12 ms] [DEVICE LOG] 2018-10-22 22:58:48.655261+0900  localhost Runner[27014]: (Flutter) flutter: ConnectionState.waiting\r\n[        ] [DEVICE LOG] 2018-10-22 22:58:48.655327+0900  localhost Runner[27014]: (Flutter) flutter: null\r\n[        ] flutter: ConnectionState.waiting\r\n...\r\n```\r\n\r\n<!-- Finally, paste the output of running `flutter doctor -v` here. -->\r\n\r\n```\r\n[✓] Flutter (Channel beta, v0.8.2, on Mac OS X 10.14 18A391, locale en-KR)\r\n    • Flutter version 0.8.2 at /Users/hyochan/flutter/sdk\r\n    • Framework revision 5ab9e70727 (6 weeks ago), 2018-09-07 12:33:05 -0700\r\n    • Engine revision 58a1894a1c\r\n    • Dart version 2.1.0-dev.3.1.flutter-760a9690c2\r\n\r\n[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)\r\n    • Android SDK at /Users/hyochan/Library/Android/sdk\r\n    • Android NDK location not configured (optional; useful for native profiling support)\r\n    • Platform android-27, build-tools 27.0.3\r\n    • ANDROID_HOME = /Users/hyochan/Library/Android/sdk\r\n    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java\r\n    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)\r\n    • All Android licenses accepted.\r\n\r\n[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)\r\n    • Xcode at /Applications/Xcode.app/Contents/Developer\r\n    • Xcode 10.0, Build version 10A255\r\n    • ios-deploy 1.9.2\r\n    • CocoaPods version 1.5.3\r\n\r\n[✓] Android Studio (version 3.1)\r\n    • Android Studio at /Applications/Android Studio.app/Contents\r\n    • Flutter plugin version 27.1.1\r\n    • Dart plugin version 173.4700\r\n    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)\r\n\r\n[!] VS Code (version 1.28.2)\r\n    • VS Code at /Applications/Visual Studio Code.app/Contents\r\n    • Flutter extension not installed; install from\r\n      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter\r\n\r\n[✓] Connected devices (1 available)\r\n    • iPhone 6 • 1D1C8F6D-7C5E-46FC-B9E2-A9B69968979F • ios • iOS 12.0 (simulator)\r\n\r\n! Doctor found issues in 1 category.\r\n```\r\n"}}
{"actor":{"display_login":"zoechi"}}