I am developing a flutter app.My flutter project shows error in factory constructor when I use DocumentSnapshot
User.dart
import 'package:cloud_firestore/cloud_firestore.dart';
class User {
final String id;
final String username;
final String email;
final String photoUrl;
final String displayname;
final String bio;
User({
this.id,
this.username,
this.email,
this.photoUrl,
this.displayname,
this.bio
});
factory User.fromDoc(DocumentSnapshot doc){
return User(
id: doc['id'],
username: doc['username'],
email: doc['email'],
photoUrl: doc['photoUrl'],
displayname: doc['displayName'],
bio: doc['bio'],
);
}
}
Error log
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
lib/models/user.dart:22:14: Error: The operator '[]' isn't defined for the class 'DocumentSnapshot'.
- 'DocumentSnapshot' is from 'package:cloud_firestore/cloud_firestore.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.0+2/lib/cloud_firestore.dart').
Try correcting the operator to an existing operator, or defining a '[]' operator.
id: doc['id'],
^
lib/models/user.dart:23:20: Error: The operator '[]' isn't defined for the class 'DocumentSnapshot'.
- 'DocumentSnapshot' is from 'package:cloud_firestore/cloud_firestore.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.0+2/lib/cloud_firestore.dart').
Try correcting the operator to an existing operator, or defining a '[]' operator.
username: doc['username'],
^
lib/models/user.dart:24:17: Error: The operator '[]' isn't defined for the class 'DocumentSnapshot'.
- 'DocumentSnapshot' is from 'package:cloud_firestore/cloud_firestore.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.0+2/lib/cloud_firestore.dart').
Try correcting the operator to an existing operator, or defining a '[]' operator.
email: doc['email'],
^
lib/models/user.dart:25:20: Error: The operator '[]' isn't defined for the class 'DocumentSnapshot'.
- 'DocumentSnapshot' is from 'package:cloud_firestore/cloud_firestore.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.0+2/lib/cloud_firestore.dart').
Try correcting the operator to an existing operator, or defining a '[]' operator.
photoUrl: doc['photoUrl'],
^
lib/models/user.dart:26:23: Error: The operator '[]' isn't defined for the class 'DocumentSnapshot'.
- 'DocumentSnapshot' is from 'package:cloud_firestore/cloud_firestore.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.0+2/lib/cloud_firestore.dart').
Try correcting the operator to an existing operator, or defining a '[]' operator.
displayname: doc['displayName'],
^
lib/models/user.dart:27:15: Error: The operator '[]' isn't defined for the class 'DocumentSnapshot'.
- 'DocumentSnapshot' is from 'package:cloud_firestore/cloud_firestore.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.0+2/lib/cloud_firestore.dart').
Try correcting the operator to an existing operator, or defining a '[]' operator.
bio: doc['bio'],
^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 896
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
Exception: Gradle task assembleDebug failed with exit code 1
Is there any way to correct this operator problem because I have to use DocumentSnapshot in various sections of my app? If there any permanent solution available to use this kind of methods?
Thank You
If you want to access the firebases DocumentSnapshot you need to access its data attribute snapshot.data. If you want to access the map behind it use snapshot.data.data
So in your example something like:
factory User.fromDoc(DocumentSnapshot doc){
return User(
id: doc.data.data['id'],
username: doc.data.data['username'],
email: doc.data.data['email'],
photoUrl: doc.data.data['photoUrl'],
displayname: doc.data.data['displayName'],
bio: doc.data.data['bio'],
);
}
}
See the One-Time Read section in the official documentation:
https://firebase.flutter.dev/docs/firestore/usage/
Related
App worked fine for the whole day, while I was frequently rebuilding it, then once I tried to build it again, I kept getting these errors. I didn't add any new dependencies, nor did I do any major changes to the code. I probably tried everything you can find when googling some of these error messages but nothing helped me. If I try to migrate code to new project, it faces the same problem.
The problem seems to be somehow related to cloud firestore as indicated by error messages, when I remove all the refferences to it in my app leaving just firebase auth it builds just fine.
debug console looke like this :
Launching lib\main.dart on Android SDK built for x86 in debug mode... Invalid depfile: C:\FlutterProjects\table_tennis_app\.dart_tool\flutter_build\742478cdbb2672c05d106c6da3c117ec\kernel_snapshot.d Invalid depfile: C:\FlutterProjects\table_tennis_app\.dart_tool\flutter_build\742478cdbb2672c05d106c6da3c117ec\kernel_snapshot.d /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.3/lib/js.dart:8:1: Error: Not found: 'dart:js' export 'dart:js' show allowInterop, allowInteropCaptureThis; ^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:2:8: Error: Not found: 'dart:html'
import 'dart:html';
^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/storage.dart:2:8: Error: Not found: 'dart:html' import 'dart:html';
^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.3/lib/js_util.dart:8:1: Error: Not found: 'dart:js_util' export 'dart:js_util'; ^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart:102:32: Error: The method 'allowInterop' isn't defined for the class 'Firestore'.
- 'Firestore' is from 'package:firebase/src/firestore.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final updateFunctionWrap = allowInterop((transaction) =>
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart:300:9: Error: The method 'allowInterop' isn't defined for the class 'DocumentReference'.
- 'DocumentReference' is from 'package:firebase/src/firestore.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((firestore_interop.DocumentSnapshotJsImpl snapshot) {
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart:304:26: Error: The method 'allowInterop' isn't defined for the class 'DocumentReference'.
- 'DocumentReference' is from 'package:firebase/src/firestore.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final errorWrapper = allowInterop((e) => controller.addError(e));
^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart:441:9: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
- 'Query' is from 'package:firebase/src/firestore.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((firestore_interop.QuerySnapshotJsImpl snapshot) {
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart:445:26: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
- 'Query' is from 'package:firebase/src/firestore.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final errorWrapper = allowInterop((e) => controller.addError(e));
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart:761:9: Error: The method 'allowInterop' isn't defined for the class 'QuerySnapshot'.
- 'QuerySnapshot' is from 'package:firebase/src/firestore.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/firestore.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((s) => callback(DocumentSnapshot.getInstance(s)));
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:51:29: Error: Method not found: 'getProperty'.
map[key] = dartify(util.getProperty(jsObject, key));
^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:73:24: Error: Method not found: 'newObject'.
final jsMap = util.newObject();
^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:75:12: Error: Method not found: 'setProperty'.
util.setProperty(jsMap, key, jsify(value));
^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:97:12: Error: Method not found: 'allowInterop'.
return allowInterop(dartObject);
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:105:10: Error: Method not found: 'callMethod'.
util.callMethod(jsObject, method, args);
^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:120:24: Error: Method not found: 'promiseToFuture'.
value = await util.promiseToFuture(thenable);
^^^^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:122:14: Error: Method not found: 'hasProperty'.
if (util.hasProperty(e, 'code')) {
^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:133:22: Error: Method not found: 'allowInterop'.
PromiseJsImpl<S>(allowInterop((
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:145:5: Error: Method not found: 'allowInterop'.
allowInterop(c.completeError);
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:153:27: Error: Method not found: 'getProperty'.
String get code => util.getProperty(_source, 'code');
^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:156:30: Error: Method not found: 'getProperty'. String get message => util.getProperty(_source, 'message');
^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:159:27: Error: Method not found: 'getProperty'. String get name => util.getProperty(_source, 'name');
^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:162:37: Error: Method not found: 'getProperty'.
Object get serverResponse => util.getProperty(_source, 'serverResponse');
^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:165:28: Error: Method not found: 'getProperty'.
String get stack => util.getProperty(_source, 'stack');
^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:176:15: Error: Method not found: 'instanceof'. return util.instanceof(object, type);
^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:180:19: Error: Undefined name 'window'. Object? start = window;
^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/utils.dart:185:18: Error: Method not found: 'getProperty'.
start = util.getProperty(start, item);
^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/auth.dart:330:25: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
- 'Auth' is from 'package:firebase/src/auth.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/auth.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final nextWrapper = allowInterop((firebase_interop.UserJsImpl? user) {
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/auth.dart:334:26: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
- 'Auth' is from 'package:firebase/src/auth.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/auth.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final errorWrapper = allowInterop((e) => changeController.addError(e));
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/auth.dart:362:9: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
- 'Auth' is from 'package:firebase/src/auth.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/auth.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((firebase_interop.UserJsImpl? user) {
^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/auth.dart:365:9: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
- 'Auth' is from 'package:firebase/src/auth.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/auth.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop(idTokenChangedController.addError),
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart:156:9: Error: The method 'allowInterop' isn't defined for the class 'DatabaseReference<T>'.
- 'DatabaseReference' is from 'package:firebase/src/database.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((update) => jsify(transactionUpdate(dartify(update))));
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart:158:28: Error: The method 'allowInterop' isn't defined for the class 'DatabaseReference<T>'.
- 'DatabaseReference' is from 'package:firebase/src/database.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final onCompleteWrap = allowInterop(
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart:291:26: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
- 'Query' is from 'package:firebase/src/database.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final callbackWrap = allowInterop((
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart:320:30: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
- 'Query' is from 'package:firebase/src/database.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
jsObject.once(eventType, allowInterop(
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart:397:24: Error: The method 'allowInterop' isn't defined for the class 'DataSnapshot'.
- 'DataSnapshot' is from 'package:firebase/src/database.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/database.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final actionWrap = allowInterop((d) => action(DataSnapshot.getInstance(d)));
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/storage.dart:312:25: Error: The method 'allowInterop' isn't defined for the class 'UploadTask'.
- 'UploadTask' is from 'package:firebase/src/storage.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/storage.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final nextWrapper = allowInterop(
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/storage.dart:318:26: Error: The method 'allowInterop' isn't defined for the class 'UploadTask'.
- 'UploadTask' is from 'package:firebase/src/storage.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/storage.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final onCompletion = allowInterop(() {
^^^^^^^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/storage.dart:329:9: Error: The method 'allowInterop' isn't defined for the class 'UploadTask'.
- 'UploadTask' is from 'package:firebase/src/storage.dart' ('/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-9.0.2/lib/src/storage.dart'). Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop(_changeController.addError),
^^^^^^^^^^^^ Unhandled exception: FileSystemException(uri=org-dartlang-untranslatable-uri:dart%3Ajs; message=StandardFileSystem only supports file:* and data:* URIs)
#0 StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)
#1 asFileUri (package:vm/kernel_front_end.dart:623:37)
#2 writeDepfile (package:vm/kernel_front_end.dart:763:21) <asynchronous suspension>
#3 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:586:9) <asynchronous suspension>
#4 starter (package:flutter_frontend_server/server.dart:85:12)
<asynchronous suspension>
#5 main (file:///C:/b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:13:24)
<asynchronous suspension>
FAILURE: Build failed with an exception.
* Where: Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1102
* What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org BUILD FAILED in 13s Exception: Gradle task assembleDebug failed with exit code 1 Exited (sigterm)
It might happen due to multiple reasons. You can try:
Delete kernel_snapshot.d and kernel_snapshot.stamp files at
flutter project \.dart_tool\flutter_build\742478cdbb2672c05d106c6da3c117ec.
You might have imported web-only dependency in my pubspec file or check if by mistake you have imported wrong file like import 'dart:html';.
Try flutter pub get because it looks like one of your packages is not found if this did not works then try flutter clean.
Seems like you are using firebase: ^9.0.2 which only supports Web platform and you are trying to build app on Android Device.
How to solve this problem. I'm new user flutter please anyone help me.
lib/screens/main.dart:93:26: Error: The argument type 'Padding' can't be assigned to the p
arameter type 'String'.
- 'Padding' is from 'package:flutter/src/widgets/basic.dart' ('/C:/src/flutter/packages/f
lutter/lib/src/widgets/basic.dart').
label: Padding(
^
lib/screens/main.dart:108:26: Error: The argument type 'Padding' can't be assigned to the
parameter type 'String'.
- 'Padding' is from 'package:flutter/src/widgets/basic.dart' ('/C:/src/flutter/packages/f
lutter/lib/src/widgets/basic.dart').
label: Padding(
^
lib/screens/main.dart:120:24: Error: The argument type 'Text' can't be assigned to the par
ameter type 'String'.
- 'Text' is from 'package:flutter/src/widgets/text.dart' ('/C:/src/flutter/packages/flutt
er/lib/src/widgets/text.dart').
label: Text(""),
^
lib/screens/main.dart:130:26: Error: The argument type 'Padding' can't be assigned to the
parameter type 'String'.
- 'Padding' is from 'package:flutter/src/widgets/basic.dart' ('/C:/src/flutter/packages/f
lutter/lib/src/widgets/basic.dart').
label: Padding(
^
lib/screens/main.dart:145:26: Error: The argument type 'Padding' can't be assigned to the
parameter type 'String'.
- 'Padding' is from 'package:flutter/src/widgets/basic.dart' ('/C:/src/flutter/packages/f
lutter/lib/src/widgets/basic.dart').
label: Padding(
^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/chewie-0.9.10/lib/src/chewie_player.dar
t:276:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'Bu
ildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/p
ackages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inh
eritFromWidgetOfExactType'.
context.inheritFromWidgetOfExactType(_ChewieControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/chewie_audio-1.0.0+1/lib/src/chewie_pla
yer.dart:101:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the cl
ass 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/p
ackages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inh
eritFromWidgetOfExactType'.
context.inheritFromWidgetOfExactType(_ChewieAudioControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to
get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 16s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 77.7s
Gradle task assembleRelease failed with exit code 1
You're trying to give your widget a Padding type instead of a String
Try this
Padding(
padding: EdgeInsets.all(8),
child: YourWidget(
label: "a string"
)
)
I am getting this error not sure where the problem is the codes look ok but
ActivityFeedItem(
{this.username,
this.userId,
this.type,
this.mediaUrl,
this.mediaId,
this.userProfileImg,
this.commentData});
factory ActivityFeedItem.fromDocument(DocumentSnapshot document) {
var data = document.data();
return ActivityFeedItem(
username: data['username'],
userId: data['userId'],
type: data['type'],
mediaUrl: data['mediaUrl'],
mediaId: data['postId'],
userProfileImg: data['userProfileImg'],
commentData: data["commentData"],
);
lib/comment_screen.dart:164:21: Error: The operator '[]' isn't defined for the class 'Object'.
'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '[]' operator.
username: data['username'],
^
lib/comment_screen.dart:165:19: Error: The operator '[]' isn't defined for the class 'Object'.
'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '[]' operator.
userId: data['userId'],
^
lib/comment_screen.dart:166:20: Error: The operator '[]' isn't defined for the class 'Object'.
'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '[]' operator.
comment: data["comment"],
^
lib/comment_screen.dart:167:22: Error: The operator '[]' isn't defined for the class 'Object'.
'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '[]' operator.
timestamp: data["timestamp"],
^
lib/comment_screen.dart:168:22: Error: The operator '[]' isn't defined for the class 'Object'.
'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '[]' operator.
avatarUrl: data["avatarUrl"],
^
FAILURE: Build failed with an exception.
Where:
Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991
What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
You should change var --> Map as follows:
Somehow Dart does not recognize data as Map at compile time.
Map data = document.data();
Try :
Map<String, dynamic> data = document.data();
I used Freezed package and need generating json . But when get response from API faced error type 'String' is not a subtype of type 'int' in type cast. This error known because my response from API String but i make integer in model
After searching to fixed solution , i found to solved this from this issue .But when build the application i get this error :
Launching lib\main.dart on Redmi Note 4 in debug mode...
Compiler message:
lib/src/network/models/utang/utang_model.freezed.dart:223:20: Error: Getter not found: '_stringToInt'.
#JsonKey(fromJson: _stringToInt, toJson: _stringFromInt)
^^^^^^^^^^^^
lib/src/network/models/utang/utang_model.freezed.dart:223:42: Error: Getter not found: '_stringFromInt'.
#JsonKey(fromJson: _stringToInt, toJson: _stringFromInt)
^^^^^^^^^^^^^^
Compiler message:
lib/src/network/models/utang/utang_model.freezed.dart:223:20: Error: Getter not found: '_stringToInt'.
#JsonKey(fromJson: _stringToInt, toJson: _stringFromInt)
^^^^^^^^^^^^
lib/src/network/models/utang/utang_model.freezed.dart:223:42: Error: Getter not found: '_stringFromInt'.
#JsonKey(fromJson: _stringToInt, toJson: _stringFromInt)
^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.
FAILURE: Build failed with an exception.
* Where:
Script 'C:\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 882
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 23s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
Model
#freezed
abstract class UtangModel with _$UtangModel {
#JsonSerializable(fieldRename: FieldRename.snake)
#JsonKey(fromJson: _stringToInt, toJson: _stringFromInt)
const factory UtangModel({
String idUtang,
UserGoogleModel pembertang,
UserGoogleModel pengutang,
int totalUtang,
int sisaUtang,
DateTime tglKembali,
String status,
String keterangan,
String selfie,
String ttd,
DateTime createdDate,
}) = _UtangModel;
factory UtangModel.fromJson(Map<String, dynamic> json) => _$UtangModelFromJson(json);
static int _stringToInt(String number) => number == null ? null : int.parse(number);
static String _stringFromInt(int number) => number?.toString();
}
I missed something ?
You have to indicate that this function is from the abstract class UtangModel:
#freezed
abstract class UtangModel with _$UtangModel {
#JsonSerializable(fieldRename: FieldRename.snake)
const factory UtangModel({
String idUtang,
UserGoogleModel pembertang,
UserGoogleModel pengutang,
#JsonKey(fromJson: UtangModel._stringToInt, toJson: UtangModel._stringFromInt)int totalUtang,
int sisaUtang,
DateTime tglKembali,
String status,
String keterangan,
String selfie,
String ttd,
DateTime createdDate,
}) = _UtangModel;
factory UtangModel.fromJson(Map<String, dynamic> json) => _$UtangModelFromJson(json);
static int _stringToInt(String number) => number == null ? null : int.parse(number);
static String _stringFromInt(int number) => number?.toString();
}
I am tried to use flutter_stetho package when it Compile the compiler shown ..
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Compiler message:
file:///home/administrator/softwares/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_stetho-0.2.2/lib/src/http_client_response.dart:4:7: Error: The non-abstract class 'StethoHttpClientResponse' is missing implementations for these members:
- HttpClientResponse.compressionState
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class StethoHttpClientResponse extends StreamView<List<int>>
^^^^^^^^^^^^^^^^^^^^^^^^
org-dartlang-sdk:///third_party/dart/sdk/lib/_http/http.dart:1967:42: Context: 'HttpClientResponse.compressionState' is defined here.
HttpClientResponseCompressionState get compressionState;
^^^^^^^^^^^^^^^^
Compiler failed on /home/administrator/projects/mobile/sampleapp/lib/main.dart
FAILURE: Build failed with an exception.
* Where:
Script '/home/administrator/softwares/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 665
* What went wrong:
Execution failed for task ':app:compileflutterBuildDebugX86'.
> Process 'command '/home/administrator/softwares/flutter/bin/flutter'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 20s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
I have just faced the same error, I'm leaving the stack trace below for reference.
For me it was caused because I left a reference to a parameter in a copy-pasted method.
I had this:
Map<String, dynamic> toJson() {
return User(
login: json['login'],
password: json['password'],
firstName: json['firstName'],
lastName: json['lastName'],
email: json['email'],
cellphone: json['cellphone'],
);
}
But the correct code is actually:
Map<String, dynamic> toJson() {
return {
'login': login,
'password': password,
'firstName': firstName,
'lastName': lastName,
'email': email,
'cellphone': cellphone,
};
}
What was odd or sneaky in my case was that Visual Studio Code was not pointing out the error after opening the file.
Also, I left the constructor method from the class I based on (copy pasted) which was User
Stack trace:
Compiler message:
lib/models/rest/user_post.dart:3:7: Error: The non-abstract class 'UserPost' is missing implementations for these members:
- UserPost.User
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class UserPost {
^^^^^^^^
lib/models/rest/user_post.dart:33:3: Context: 'UserPost.User' is defined here.
User({
^^^^
lib/models/rest/user_post.dart:15:14: Error: Getter not found: 'json'.
login: json['login'],
^^^^
lib/models/rest/user_post.dart:16:17: Error: Getter not found: 'json'.
password: json['password'],
^^^^
lib/models/rest/user_post.dart:17:18: Error: Getter not found: 'json'.
firstName: json['firstName'],
^^^^
lib/models/rest/user_post.dart:18:17: Error: Getter not found: 'json'.
lastName: json['lastName'],
^^^^
lib/models/rest/user_post.dart:19:14: Error: Getter not found: 'json'.
email: json['email'],
^^^^
lib/models/rest/user_post.dart:20:18: Error: Getter not found: 'json'.
cellphone: json['cellphone'],
^^^^