Not able to login with a Google email in Flutter - flutter

I'm trying to login in Flutter and this is the error I'm getting when I try to login with a Google email:
E/flutter (26329): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
`enter code here`E/flutter (26329): Receiver: null
E/flutter (26329): Tried calling: []("email")
E/flutter (26329): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (26329): #1 DocumentSnapshot.[] (package:cloud_firestore/src/document_snapshot.dart:29:42)
E/flutter (26329): #2 new User.fromDocument (package:buddiesgram/models/user.dart:23:17)
E/flutter (26329): #3 _HomePageState.saveUserInfoFirestore (package:buddiesgram/pages/HomePage.dart:83:26)
E/flutter (26329): <asynchronous suspension>
E/flutter (26329): #4 _HomePageState.controlSignIn (package:buddiesgram/pages/HomePage.dart:54:13)
E/flutter (26329): #5 _HomePageState.initState.<anonymous closure> (package:buddiesgram/pages/HomePage.dart:40:9)
E/flutter (26329): #6 _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter (26329): #7 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (26329): #8 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter (26329): #9 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (26329): #10 _DelayedData.perform (dart:async/stream_impl.dart:594:14)
E/flutter (26329): #11 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:710:11)
E/flutter (26329): #12 _PendingEvents.schedule.<anonymous closure> *emphasized text*(dart:async/stream_impl.dart:670:7)
E/flutter (26329): #13 _rootRun (dart:async/zone.dart:1180:38)
E/flutter (26329): #14 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (26329): #15 _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter (26329): #16 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)`**`*enter code here*`**`
E/flutter (26329): #17 _rootRun (dart:async/zone.dart:1184:13)
E/flutter (26329): #18 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (26329): #19 _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter (26329): #20 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
E/flutter (26329): #21 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter (26329): #22 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
E/flutter (26329):
What am I missing?

Please include a code snippet of what you are trying to do
In my understanding of your stackTrace you are trying to call list on a null object like this:
final UserData userData = someObjectHere;
function login(UserData userData){
//The problem is that userData might be null which causes your issue
String email = userData[]("Email");
}
You're solution might be to use null aware operators or to manually check whether the object you're calling a method on is not null.
String email = userData?.[]("Email");
or
if(userData != null) String email = userData?.[]("Email");

Related

flutter showing Unhandled Exception: FormatException: Filter error, bad data error

when I am trying to make an HTTP request in flutter I am receiving these errors on a particular API and I am unable to figure out what it means and how to resolve this error is it API is working properly in postman and browser
> E/flutter (15337): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: FormatException: Filter error, bad data
E/flutter (15337): #0 _FilterImpl.processed (dart:io-patch/filter_patch.dart:11:32)
E/flutter (15337): #1 _FilterSink.addSlice (dart:io/data_transformer.dart:537:29)
E/flutter (15337): #2 _FilterSink.add (dart:io/data_transformer.dart:521:5)
E/flutter (15337): #3 _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:72:18)
E/flutter (15337): #4 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
E/flutter (15337): #5 _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter (15337): #6 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (15337): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (15337): #8 CastStreamSubscription._onData (dart:_internal/async_cast.dart:85:11)
E/flutter (15337): #9 _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter (15337): #10 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (15337): #11 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (15337): #12 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter (15337): #13 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (15337): #14 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (15337): #15 _HandleErrorStream._handleData (dart:async/stream_pipe.dart:256:10)
E/flutter (15337): #16 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (15337): #17 _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter (15337): #18 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (15337): #19 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (15337): #20 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter (15337): #21 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
E/flutter (15337): #22 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11)
E/flutter (15337): #23 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:663:7)
E/flutter (15337): #24 _rootRun (dart:async/zone.dart:1346:47)
E/flutter (15337): #25 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (15337): #26 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
E/flutter (15337): #27 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
E/flutter (15337): #28 _rootRun (dart:async/zone.dart:1354:13)
E/flutter (15337): #29 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (15337): #30 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
E/flutter (15337): #31 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
E/flutter (15337): #32 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (15337): #33 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (15337):
I have tried adding other API which is am using in my application and code is working properly but for it is giving above exception and stops after HTTP call.
Future<Null> getNewHomeData() async {
setState(() {
loading = true;
});
final response = await http.get(Uri.parse(Uri.encodeFull(APIs.url_HomePage)));
print(response.statusCode);
print(response.body);
try {
print(response.body);
if(response.statusCode == 200){
final home = homeNewFromJson(response.body);
homeBanner = home.advImg;
homeContent = home.infoText;
shopCat = home.shopCat;
storeImg = home.storeImg;
topSellings = home.topSellings;
modularFurniture = home.modularFurniture;
decorFurniture = home.decorFurniture;
banner1 = home.banner1;
banner2 = home.banner2;
banner3 = home.banner3;
banner4 = home.banner4;
banner5 = home.banner5;
}
} on Exception catch (e) {
print(e);
}

image upload using http multipart. if image is null then getting error

on tap submit subbmit method call .
[1]: https://i.stack.imgur.com/glYah.png
error :
successful
E/flutter (11575): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: The method 'readAsBytesSync' was called on null.
E/flutter (11575): Receiver: null
E/flutter (11575): Tried calling: readAsBytesSync()
E/flutter (11575): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter (11575): #1 _Delivery_DetailsState.submitForm (package:shop_me/src/screens/product_delivery/ui/delivery_detail.dart:500:37)
E/flutter (11575): #2 _Delivery_DetailsState.build. (package:shop_me/src/screens/product_delivery/ui/delivery_detail.dart:384:33)
E/flutter (11575): #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:21)
E/flutter (11575): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (11575): #5 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:607:11)
E/flutter (11575): #6 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
E/flutter (11575): #7 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:267:7)
E/flutter (11575): #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:157:27)
E/flutter (11575): #9 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:443:20)
E/flutter (11575): #10 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:419:22)
E/flutter (11575): #11 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:287:11)
E/flutter (11575): #12 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:374:7)
E/flutter (11575): #13 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:338:5)
E/flutter (11575): #14 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:296:7)
E/flutter (11575): #15 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:279:7)
E/flutter (11575): #16 _rootRunUnary (dart:async/zone.dart:1370:13)
E/flutter (11575): #17 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (11575): #18 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (11575): #19 _invoke1 (dart:ui/hooks.dart:182:10)
E/flutter (11575): #20 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:282:7)
E/flutter (11575): #21 _dispatchPointerDataPacket (dart:ui/hooks.dart:96:31)
E/flutter (11575):

How to save values from query in shared_preferences with conditional statement flutter

I have a query function for data from the database that comes with the id number from the database, then the id is saved in shared_preferences in case the new id that comes from the database is larger than the old id that was in the shared_preferences previously.But after running the code, the following problem comes:
E/flutter (30884): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: Class 'String' has no instance method '<'.
E/flutter (30884): Receiver: ""
E/flutter (30884): Tried calling: <(7)
E/flutter (30884): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (30884): #1 AddCommentsState.getLogin.<anonymous closure> (package:flutter_apptestqeuriy/AddComment.dart:84:46)
E/flutter (30884): #2 State.setState (package:flutter/src/widgets/framework.dart:1240:30)
E/flutter (30884): #3 AddCommentsState.getLogin (package:flutter_apptestqeuriy/AddComment.dart:78:5)
E/flutter (30884): <asynchronous suspension>
E/flutter (30884): #4 AddCommentsState.initState.<anonymous closure> (package:flutter_apptestqeuriy/AddComment.dart:57:9)
E/flutter (30884): #5 interval.function (package:flutter_apptestqeuriy/AddComment.dart:21:9)
E/flutter (30884): #6 _rootRun (dart:async/zone.dart:1182:47)
E/flutter (30884): #7 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (30884): #8 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (30884): #9 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter (30884): #10 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (30884): #11 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (30884): #12 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter (30884): #13 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (30884): #14 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter (30884): #15 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter (30884): #16 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (30884):
This is the code used to query from the database:
var user_id;
var my_pre_id;
Future<String> getLogin() async {
var response = await http.get(Uri.encodeFull("http://xxxxxxxxxxx/Application.php"),);
setState(() {
var convertDataToJson = json.decode(response.body);
data = convertDataToJson['result'];
if (data != null) {
user_id = int.parse(data[0]['id']);
my_pre_id = _myPreferences.id;
if (my_pre_id == null || my_pre_id < user_id ){
_myPreferences.id = user_id;
_myPreferences.commit();
// print("tappeeeeedddd $my_pre_id");
}
}
});
}
Does anyone know the cause of the problem?
I think the issue comes from my_pre_id < user_id where my_pre_id is actually a String. You might want to do an int.parse() on it as well or change its type in the class.

Unhandled Exception: RangeError (index): Index out of range: index should be less than

I am having a problem when trying to save a pdf using the "pdf_dart" library.
I assume the problem is linked to the image I'm downloading from the internet to try to attach to the pdf but I'm not sure what it is.
CODE
import 'dart:io';
import 'package:app_formulario/models/Customer.dart';
import 'package:path_provider/path_provider.dart';
import 'package:pdf/pdf.dart' as pdfDart;
import 'package:pdf/widgets.dart';
import 'package:image/image.dart' as imageDart;
import 'package:flutter/material.dart' as materialDart;
import 'package:http/http.dart' as http;
class PDFBloc {
PDFBloc() {
final Document pdf = Document();
http
.get(
"https://clsp.com.br/wp-content/uploads/2018/05/logo-clsp-500px.png")
.then((onValue) {
final image = pdfDart.PdfImage(
pdf.document,
image: onValue.bodyBytes,
width: 300,
height: 150,
);
pdf.addPage(Page(build: (Context context) {
return Center(
child: Image(image),
); // Center
}));
criarPDF(pdf);
});
}
void criarPDF(Document pdf) async {
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
appDocPath = "/storage/emulated/0/Android/data/com.rwrd.app_formulario";
final File file = File('$appDocPath/example.pdf');
file.writeAsBytesSync(pdf.save());
}
The error happens right when I am going to save the pdf with the image, that is, apparently the image is downloaded normally, however when inserting it in the pdf and trying to save it, the error is caused.
I don't know if the way I'm saving is the correct one, maybe that's it, but unfortunately I can't access the file folder without going all the way through it.
The error stack
E/flutter (18670): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: RangeError (index): Index out of range: index should be less than 6307: 6308
E/flutter (18670): #0 Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart:2209:7)
E/flutter (18670): #1 PdfImage._prepare
package:pdf/src/image.dart:183
E/flutter (18670): #2 PdfObject._write
package:pdf/src/object.dart:53
E/flutter (18670): #3 PdfOutput.write
package:pdf/src/output.dart:69
E/flutter (18670): #4 SetMixin.forEach (dart:collection/set.dart:148:30)
E/flutter (18670): #5 PdfDocument._write
package:pdf/src/document.dart:168
E/flutter (18670): #6 PdfDocument.save
package:pdf/src/document.dart:176
E/flutter (18670): #7 Document.save
package:pdf/widgets/document.dart:71
E/flutter (18670): #8 PDFBloc.criarPDF
package:app_formulario/blocs/pdfBloc.dart:53
E/flutter (18670): <asynchronous suspension>
E/flutter (18670): #9 new PDFBloc.<anonymous closure>
package:app_formulario/blocs/pdfBloc.dart:35
E/flutter (18670): #10 _rootRunUnary (dart:async/zone.dart:1134:38)
E/flutter (18670): #11 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (18670): #12 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
E/flutter (18670): #13 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
E/flutter (18670): #14 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
E/flutter (18670): #15 Future._completeWithValue (dart:async/future_impl.dart:524:5)
E/flutter (18670): #16 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:32:15)
E/flutter (18670): #17 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:290:13)
E/flutter (18670): #18 _withClient (package:http/http.dart)
E/flutter (18670): <asynchronous suspension>
E/flutter (18670): #19 get
package:http/http.dart:46
E/flutter (18670): #20 new PDFBloc
package:app_formulario/blocs/pdfBloc.dart:18
E/flutter (18670): #21 FormBloc._recoverCustomerInformations
package:app_formulario/blocs/formBloc.dart:37
E/flutter (18670): #22 _rootRunUnary (dart:async/zone.dart:1134:38)
E/flutter (18670): #23 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (18670): #24 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter (18670): #25 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
E/flutter (18670): #26 _DelayedData.perform (dart:async/stream_impl.dart:593:14)
E/flutter (18670): #27 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:709:11)
E/flutter (18670): #28 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:669:7)
E/flutter (18670): #29 _rootRun (dart:async/zone.dart:1122:38)
E/flutter (18670): #30 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (18670): #31 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (18670): #32 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
E/flutter (18670): #33 _rootRun (dart:async/zone.dart:1126:13)
E/flutter (18670): #34 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (18670): #35 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (18670): #36 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
E/flutter (18670): #37 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter (18670): #38 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
E/flutter (18670):
change pdf image widget to this,
final image = pdfDart.PdfImage.jpeg(
pdf.document,
image: onValue.bodyBytes,
);
now, your image should appear in the pdf but you will have to resize your image if you want to fix height and width.

Error while using games_services plugin: Unhandled Exception: PlatformException(error, 4: 4: , null)

I wanted to use google play services in my flutter application for which i used games_services plugin. I followed all the steps in this medium post. But it still gave me this error.
E/flutter (27643): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, 4: 4: , null)
E/flutter (27643): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569)
E/flutter (27643): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321)
E/flutter (27643): <asynchronous suspension>
E/flutter (27643): #2 GamesServices.signIn (package:games_services/games_services.dart:52)
E/flutter (27643): #3 _WelcomePageState.build.<anonymous closure> (package:quizbee/pages/home/welcome.dart:182)
E/flutter (27643): #4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706)
E/flutter (27643): #5 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789)
E/flutter (27643): #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182)
E/flutter (27643): #7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486)
E/flutter (27643): #8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282)
E/flutter (27643): #9 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199)
E/flutter (27643): #10 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467)
E/flutter (27643): #11 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76)
E/flutter (27643): #12 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117)
E/flutter (27643): #13 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379)
E/flutter (27643): #14 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115)
E/flutter (27643): #15 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101)
E/flutter (27643): #16 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218)
E/flutter (27643): #17 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198)
E/flutter (27643): #18 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156)
E/flutter (27643): #19 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102)
E/flutter (27643): #20 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86)
E/flutter (27643): #21 _rootRunUnary (dart:async/zone.dart:1138)
E/flutter (27643): #22 _CustomZone.runUnary (dart:async/zone.dart:1031)
E/flutter (27643): #23 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933)
E/flutter (27643): #24 _invoke1 (dart:ui/hooks.dart:273)
E/flutter (27643): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:182)
Thank You in advance.