Я получаю эту ошибку при попытке получить пользовательские данные из cloud_firestore, но я получаю эту ошибку, только когда пользователи впервые входят в приложение и переходят на экран профиля. если я перезапущу или перезапущу приложение в горячем режиме, а в состоянии входа в систему ошибка исчезнет .
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══
flutter: The following NoSuchMethodError was thrown building StreamBuilder<DocumentSnapshot>(dirty, state:
flutter: _StreamBuilderBaseState<DocumentSnapshot, AsyncSnapshot<DocumentSnapshot>>#f33a1):
flutter: The method '[]' was called on null.
flutter: Receiver: null
flutter: Tried calling: []("name")
flutter:
flutter: User-created ancestor of the error-causing widget was:
flutter: SliverFillRemaining
flutter: file:///Users/ishangavidusha/Development/MUD/mud_mobile_app/lib/screens/profile_screen.dart:102:13
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
flutter: #1 new User.from (package:mud_mobile_app/models/user_model.dart:23:22)
flutter: #2 _ProfileScreenState.build.<anonymous closure> (package:mud_mobile_app/screens/profile_screen.dart:107:38)
flutter: #3 StreamBuilder.build (package:flutter/src/widgets/async.dart:425:74)
flutter: #4 _StreamBuilderBaseState.build (package:flutter/src/widgets/async.dart:125:48)
flutter: #5 StatefulElement.build (package:flutter/src/widgets/framework.dart:4047:27)
flutter: #6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3941:15)
flutter: #7 Element.rebuild (package:flutter/src/widgets/framework.dart:3738:5)
flutter: #8 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2348:33)
flutter: #9 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:760:20)
flutter: #10 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:280:5)
flutter: #11 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1033:15)
flutter: #12 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:975:9)
flutter: #13 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:891:5)
flutter: #17 _invoke (dart:ui/hooks.dart:249:10)
flutter: #18 _drawFrame (dart:ui/hooks.dart:207:3)
flutter: (elided 3 frames from package dart:async)
Снимок экрана эмулятора
Иэто пользовательская модель, которую я использую>
class User {
final String id;
final String name;
final String profileImageUrl;
final String email;
User({this.id, this.name, this.profileImageUrl, this.email});
factory User.fromDoc(DocumentSnapshot doc) {
return User(
id: doc.documentID,
name: doc['name'],
profileImageUrl: doc['profileImageUrl'],
email: doc['email'],
);
}
}
FutureBuilder>
SliverFillRemaining(
child: FutureBuilder(
future: _getUserData(widget.userId),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (!snapshot.hasData) {
return Padding(
padding: const EdgeInsets.all(50.0),
child: Center(
child: CircularProgressIndicator(),
),
);
}
User user = User.fromDoc(snapshot.data);
return Column(
children: <Widget>[
Padding(...),
Container(...),
Container(...),
],
);
}
)
)
И возвращение Funtion DocumentSnapshot>
Future<DocumentSnapshot> _getUserData(userId) async {
return Firestore.instance.collection('users').document(userId).get();
}