我正在尝试向Firebase提交表单,但收到错误The getter 'user' was called on null。我不知道如何解决这个问题。一切看起来都很好,不知道为什么会出现此错误。我试着做一个
empty String like this String user = '';
但它仍然给了我错误。
这是我将数据上传到 Firebase 的学员
import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_geocoder/geocoder.dart';
import 'package:image_picker/image_picker.dart';
import 'package:location/location.dart';
class AuthProvider extends ChangeNotifier {
FirebaseAuth _authData = FirebaseAuth.instance;
File image;
bool isPicAvail = false;
String pickerError = '';
double storeLatitude;
double storeLongitude;
String storeAddress;
String placeName;
String error = '';
bool loading = false;
String email;
Future<void>saveVendorData({
String url, shopName, number, aboutShop, cnicNumber, ntnNumber}){
User user = FirebaseAuth.instance.currentUser;
DocumentReference _vendors = FirebaseFirestore.instance.collection('vendors').doc(user.uid);
_vendors.set({
'uid': user.uid,
'email': this.email,
'shopName': shopName,
'number': number,
'aboutShop': aboutShop,
'cnicNumber': cnicNumber,
'ntnNumber': ntnNumber,
'address': '${this.placeName}: ${this.storeAddress}',
'location': GeoPoint(this.storeLatitude, this.storeLongitude),
'shopOpen': true,
'rating': 0.00,
'totalRating': 0
});
return null;
}
}
错误出现在这一行的表格中。credential.user?.uid!=null
TextButton(
onPressed: () {
if(_authData.isPicAvail == true) {
if (_formKey.currentState.validate()) {
setState(() {
loading = true;
});
_authData.registerVendor(email,password).then((credential){
if(credential.user?.uid!=null){
uploadFile(_authData.image.path).then((url){
if(url!=null){
_authData.saveVendorData(
url: url,
number: number,
shopName: shopName,
aboutShop: _aboutShopController.text,
cnicNumber: _cnicNumberController.text,
ntnNumber: _ntnNumberController.text,
).then((value) {
setState(() {
// _formKey.currentState.reset();
loading = false;
});
Navigator.pushReplacementNamed(context, HomeScreen.id);
});
}else{
scaffoldMessage('Failed to upload Shop Pic');
}
});
}else{
scaffoldMessage(_authData.error);
}
});
}
}else{
scaffoldMessage('Please add Shop Pic');
}
},
child: Text('Register'),
style: TextButton.styleFrom(
primary: Colors.black,
backgroundColor: Colors.greenAccent,
onSurface: Colors.grey,
),
),
这是错误
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
Parameter format not correct -
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
D/FlutterLocationService( 5018): Creating service.
D/FlutterLocationService( 5018): Binding to location service.
D/EGL_emulation( 5018): eglMakeCurrent: 0xa6285e00: ver 2 0 (tinfo 0x8c340180)
Debug service listening on ws://127.0.0.1:51256/Syc26foQ1_0=/ws
Syncing files to device Android SDK built for x86...
D/EGL_emulation( 5018): eglMakeCurrent: 0xa38f76e0: ver 2 0 (tinfo 0x8d4a9280)
D/EGL_emulation( 5018): eglMakeCurrent: 0xa6285e00: ver 2 0 (tinfo 0x8c340180)
D/EGL_emulation( 5018): eglMakeCurrent: 0xa38f76e0: ver 2 0 (tinfo 0x8d4a9280)
D/EGL_emulation( 5018): eglMakeCurrent: 0xa6285e00: ver 2 0 (tinfo 0x8c340180)
D/EGL_emulation( 5018): eglMakeCurrent: 0xa38f76e0: ver 2 0 (tinfo 0x8d4a9280)
I/zygote ( 5018): Do partial code cache collection, code=60KB, data=53KB
I/zygote ( 5018): After code cache collection, code=60KB, data=53KB
I/zygote ( 5018): Increasing code cache capacity to 256KB
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/ListenableEditingState( 5018): a listener was added to EditingState while a batch edit was in progress
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/zygote ( 5018): Do full code cache collection, code=122KB, data=89KB
I/zygote ( 5018): After code cache collection, code=94KB, data=53KB
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/ListenableEditingState( 5018): a listener was added to EditingState while a batch edit was in progress
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/zygote ( 5018): Do partial code cache collection, code=121KB, data=82KB
I/zygote ( 5018): After code cache collection, code=121KB, data=82KB
I/zygote ( 5018): Increasing code cache capacity to 512KB
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/ListenableEditingState( 5018): a listener was added to EditingState while a batch edit was in progress
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/ListenableEditingState( 5018): a listener was added to EditingState while a batch edit was in progress
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): clearMetaKeyStates on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
I/TextInputPlugin( 5018): Composing region changed by the framework. Restarting the input method.
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 5018): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 5018): endBatchEdit on inactive InputConnection
W/System ( 5018): Ignoring header X-Firebase-Locale because its value was null.
E/flutter ( 5018): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: The getter 'user' was called on null.
E/flutter ( 5018): Receiver: null
E/flutter ( 5018): Tried calling: user
E/flutter ( 5018): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter ( 5018): #1 _RegisterationFormState.build.<anonymous closure>.<anonymous closure> (package:vendorapp/widgets/registertion_form.dart:337:41)
E/flutter ( 5018): #2 _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter ( 5018): #3 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter ( 5018): <asynchronous suspension>
E/flutter ( 5018):
I/zygote ( 5018): Background concurrent copying GC freed 35177(1436KB) AllocSpace objects, 0(0B) LOS objects, 57% free, 1140KB/2MB, paused 5.919ms total 30.413ms
D/EGL_emulation( 5018): eglMakeCurrent: 0xa6285e00: ver 2 0 (tinfo 0x8c340180)