hydrated_bloc: Unhandled Exception: Null check operator used on a null value - flutter

I am trying to use the hydrated_bloc package to persist a Bloc state. I already setup everything but when I try to initialize the HydratedStorage, I get an error saying Null check operator used on a null value
This is the initialization code.
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: await getTemporaryDirectory(),
);
This is the full stack trace
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
#0 MethodChannel.binaryMessenger
package:flutter/…/services/platform_channel.dart:121
#1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:146
#2 MethodChannel.invokeMethod
package:flutter/…/services/platform_channel.dart:329
#3 MethodChannelPathProvider.getApplicationDocumentsPath
package:path_provider_platform_interface/src/method_channel_path_provider.dart:50
#4 getApplicationDocumentsDirectory
package:path_provider/path_provider.dart:138
#5 main
package:main.dart:50
#6 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:145:25)
#7 _rootRun (dart:async/zone.dart:1428:13)
#8 _CustomZone.run (dart:async/zone.dart:1328:19)
#9 _runZoned (dart:async/zone.dart:1863:10)
#10 runZonedGuarded (dart:async/zone.dart:1851:12)
#11 _runMainZoned.<anonymous closure> (<…>
Reloaded 1 of 1651 libraries in 1,207ms.

Related

Firebase OTP was working but suddenly this error appears

I am trying to use firebase OTP verification
I get this error when sending firebase OTP it was working
but suddenly this error appears
E/FirebaseAuth(17209): [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 API key not valid. Please pass a valid API key.
E/flutter (17209): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'String'
E/flutter (17209): #0 MethodChannelFirebaseAuth.verifyPhoneNumber.<anonymous closure> (package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart:660:35)
E/flutter (17209): #1 _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (17209): #2 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (17209): #3 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (17209): #4 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (17209): #5 _HandleErrorStream._handleData (dart:async/stream_pipe.dart:253:10)
E/flutter (17209): #6 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (17209): #7 _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (17209): #8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (17209): #9 _DelayedData.perform (dart:async/stream_impl.dart:515:14)
E/flutter (17209): #10 _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
E/flutter (17209): #11 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
E/flutter (17209): #12 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (17209): #13 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
How to solve that ?

I tried using carousel_slider in my flutter project, it works but I get this warning in my debug console. What can I do to eradicate this?

The error is coming from the package
The error is coming from line 135
This is the warning I get from my debug console
This happens as the carousel slides
E/flutter (13716): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Null
check operator used on a null value
E/flutter (13716): #0 CarouselSliderState.getTimer.<anonymous closure>
package:carousel_slider/carousel_slider.dart:135
E/flutter (13716): #1 _rootRunUnary (dart:async/zone.dart:1436:47)
E/flutter (13716): #2 _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter (13716): #3 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
E/flutter (13716): #4 _CustomZone.bindUnaryCallbackGuarded.<anonymous closure>
(dart:async/zone.dart:1281:26)
E/flutter (13716): #5 _rootRunUnary (dart:async/zone.dart:1444:13)
E/flutter (13716): #6 _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter (13716): #7 _CustomZone.bindUnaryCallback.<anonymous closure>
(dart:async/zone.dart:1265:26)
E/flutter (13716): #8 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:395:19)
E/flutter (13716): #9 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:426:5)
E/flutter (13716): #10 _RawReceivePortImpl._handleMessage (dart:isolate-
patch/isolate_patch.dart:192:12)
E/flutter (13716):
According to the error and the screenshot, either carouselState, pageController or page is null, and you are using null check operator (!) to say that these variables can not be null. You can check these variables if they are null or not. Or you can use nullable operator (?) instead of null check operator (!).

Extract row data from csv file. Flutter

I'm having a file containing multiple data in different rows, where in the first row is having some of the ANSI values and the other rows is having UTF-8 related values.
I was hoping to extract only the first row and decode the ANSI value with the help of the ascii.decoder and in the other rows with the help of utf-8.decoder.
I successfully did the decode when i removed the first row from the csv file manually and vice versa but how to do that programmatically?
This is what I'm trying to do
final ackFile = File(entities[i].path).openRead(); //To read the file
final ackFields = await ackFile.transform(utf8.decoder).transform(const CsvToListConverter()).toList(); //To extract it I'm getting error
//also here
final ackFile = File(entities[i].path).openRead().transform(utf8.decoder).transform(LineSplitter()).forEach((element) => print("Element is $element")); //When trying to read the csv file line by line
I'm getting an error stating as
I/flutter (22362): The supplied value (512.000000pt) will be discarded and treated as if it had not been specified.
E/flutter (22362): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FormatException: Unexpected extension byte (at offset 82)
E/flutter (22362): #0 _Utf8Decoder.convertChunked (dart:convert-patch/convert_patch.dart:1893:7)
E/flutter (22362): #1 _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:314:28)
E/flutter (22362): #2 _Utf8ConversionSink.add (dart:convert/string_conversion.dart:310:5)
E/flutter (22362): #3 _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:72:18)
E/flutter (22362): #4 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
E/flutter (22362): #5 _rootRunUnary (dart:async/zone.dart:1436:47)
E/flutter (22362): #6 _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter (22362): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
E/flutter (22362): #8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter (22362): #9 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (22362): #10 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
E/flutter (22362): #11 _StreamController._add (dart:async/stream_controller.dart:607:7)
E/flutter (22362): #12 _StreamController.add (dart:async/stream_controller.dart:554:5)
E/flutter (22362): #13 _FileStream._readBlock.<anonymous closure> (dart:io/file_impl.dart:98:19)
E/flutter (22362): #14 _rootRunUnary (dart:async/zone.dart:1436:47)
E/flutter (22362): #15 _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter (22362): <asynchronous suspension>
E/flutter (22362):

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.

Flutter/Dart compiler in IntelliJ IDea throwing `NoSuchMethodError: The getter 'file' was called on null.`

When trying to compile/run my Flutter project in IntelliJ IDEA I get this error (with no hint what part of my code it relates to). Any ideas please? Thanks!!
Unhandled exception:
NoSuchMethodError: The getter 'file' was called on null.
Receiver: null
Tried calling: file
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1 ProgramCompiler.visitAssertStatement (package:dev_compiler/src/kernel/compiler.dart:3468:59)
#2 ProgramCompiler._initializeFields (package:dev_compiler/src/kernel/compiler.dart:1521:20)
#3 ProgramCompiler._emitConstructorBody (package:dev_compiler/src/kernel/compiler.dart:1392:14)
#4 ProgramCompiler._emitConstructor.<anonymous closure>.<anonymous closure> (package:dev_compiler/src/kernel/compiler.dart:1355:19)
#5 ProgramCompiler._superDisallowed (package:dev_compiler/src/kernel/compiler.dart:3122:24)
#6 ProgramCompiler._emitConstructor.<anonymous closure> (package:dev_compiler/src/kernel/compiler.dart:1354:15)
#7 ProgramCompiler._withLetScope (package:dev_compiler/src/kernel/compiler.dart:2096:25)
#8 ProgramCompiler._withCurrentFunction (package:dev_compiler/src/kernel/compiler.dart:3112:18)
#9 ProgramCompiler._emitConstructor (package:dev_compiler/src/kernel/compiler.dart:1352:16)
#10 ProgramCompiler._defineConstructors (package:dev_compiler/src/kernel/compiler.dart:972:38)
#11 ProgramCompiler._emitClassDeclaration (package:dev_compiler/src/kernel/compiler.dart:567:19)
#12 ProgramCompiler._emitClass (package:dev_compiler/src/kernel/compiler.dart:510:21)
#13 List.forEach (dart:core-patch/growable_array.dart:282:8)
#14 ProgramCompiler._emitLibrary (package:dev_compiler/src/kernel/compiler.dart:459:23)
#15 List.forEach (dart:core-patch/growable_array.dart:282:8)
#16 ProgramCompiler.emitModule (package:dev_compiler/src/kernel/compiler.dart:345:15)
#17 JavaScriptBundler.compile (package:frontend_server/src/javascript_bundle.dart:133:33)
<asynchronous suspension>
....
Finished with error: the Dart compiler exited unexpectedly.
Failed to compile application.