Response isn't a type, cannot and expected to find ';' - dart

I'm trying to send a post request within dart with the following code.
Future<Response> post (url,
{
headers, // My Map<String, String> for header info
body // My Map<String, String> for body info
})
return JSON.jsonDecode(post);
I expect it to send, however, I get two errors.
The name response isn't a type, and cant be used as a type argument, when I hover over "Response" and
expected to find ;, when I hover over "post".
I also get green underlining in android studio saying avoid unnecessary statements

This problem happens in Computers with low specs which makes android studio take time to recognize new input. Waiting will fix the issue, and you can speed this "recognition" process by clicking on the type Response in you case which will make the editor focus on it. And also add parenthesis and commas in correct way before adding new code as Dart Analyzer will quickly get confused and fill your editor with error messages.

I encountered the same issue, and I found that rerunning flutter pub get helped as that command makes sure the Http library gets downloaded.

Related

What are the actual differences between the print() vs debugPrint() and log() in Flutter?

I am trying to create a util for logging.
I need to know the actual differences between print() vs debugPrint() and log().
Many answers I have seen are outdated or confusing. Also, some upvoted answers are contradict.
I am trying to print error messages in red color. I am using ANSI code to achieve it.
debugPrint("\x1B[31m HelloDebug \x1B[0m");
The above one print in red color.
But when i do the same using log(), its not printing in red color. Its escaping the ANSI code.
One thing I found out was log() has error parameter.
If i pass something as error , it handles red color by default.
Here in the first one using log, red is not coming because ANSI code is ignored. But in debugPrint using it's working fine. In third one it takes error red by default. But extra line is added even for empty string message.
Code:
Output:
Is it possible use ANSI code for making color text using log?
Because I have other ANSI code to make different color text.
I dont want use debugPrint because if I print some thing too frequently , the system ignore the logs.
After digging some time I found out that log function is implemented in c++ in the dart runtime.As the log function is external function in dart sdk.
external void log(
String message, {
DateTime? time,
int? sequenceNumber,
int level = 0,
String name = '',
Zone? zone,
Object? error,
StackTrace? stackTrace,
});
https://github.com/dart-lang/sdk/blob/main/runtime/lib/developer.cc
Also I see some different answers while digging.
The below answer says debugPrint only available inside widget class. Is it still true?
https://stackoverflow.com/a/52241553/9248098
EDIT:
While using debugPrint and when I launch app from Android studio terminal, the ANSI color is working in android but when I run it same in iOS its escaping the characters in same Android Studio terminal.
If ANSI code support is based on terminal support, I couldn't figure out why its having issue in same terminal in iOS.
It is well explained in this page Debugging Flutter apps programmatically
debugPrint() is similar to print() but with a throttles applied to prevents being dropped by Android’s kernel.
If you have linter setup on VSCode or other IDE, you will see this warning whenever you use print in your code. For more information, you can refer to Avoid print calls in production code.
To avoid the lint error, you can use kDebugMode with print or debugPrint instead.
if (kDebugMode) {
print('test print');
}
// OR
debugPrint('test debugPrint');
As for log(), it actually allows you to include more information on the logging output. For example, you can add the runtimeType and the relevant object in the log that can help you in debugging the code.
log(
'test log',
name: runtimeType.toString(),
error: myObj,
);
** btw I tried log with ANSI code log("\x1B[31m HelloDebug \x1B[0m");, it is working as expected.

How to expend tAssertCatcher to catch more errors than its default in talend?

I have a job which when I run it- I get this:
[ERROR] 11:47:54 org.talend.components.snowflake.runtime.SnowflakeRowStandalone- Query execution has
failed. Please validate your query.
net.snowflake.client.jdbc.SnowflakeSQLException: Execution error in store procedure
SP_GENERAL:
Numeric value '' is not recognized
but when I'm trying to catch this error- I cant.
I tried tAssertCatcher, tLogCatcher, tStatCatcher- and nothing has worked.
could anybody help please?
ok, finally I got a solution.
tAssertCatcher does not catch errors from stored procedures, so I created a joblet which contain the tAssertCatcher AND in addition, added in there:
input with schema almost identical to tAssertCatcher's schema:
moment, pid, project, job, language, origin, status, substatus, errorCode, errorMessage.
now- I connected between the tDBrow component which I want to catch error from this process- with Reject row to the joblet, and pass errorCode and errorMessage- this will be the exception and description.
in the schema I used tMap to add variables values to almost all the columns:
pid, status, jobName, projectName and the rest I passed hardcoded.
finally I got a solution... every time I'll have error in stored procedure- I'll get 2 detailed records: one that I created manually, and the another one is UNEXPECTED-EXCEPTION.
the additional part in the joblet

Dart Language: how to convert a String into a Transferable (ByteBuffer)

I'll be using window.postMessage("", "*", [transferableData]) to send data between two browser windows. However, I didn't find any straight answer on how to convert types into Transferables.
So, in order for me to start learning this, it would be great to know how to convert a simple String into an Transferable (ByteBuffer) and read it on the other side (the side that is getting the message with the data). This would help me solving my problem and learning about this concept.
IMPORTANT UPDATE:
This question led me here: Dart Language: printing reports
Transferable Objects are not yet implemented on Dart VM (http://dartbug.com/4149). That means, if you're running your application via Dartium (Dart VM) the other window will be receiving and processing the first argument of postMessage, and not the Transferable Object. However, JavaScript does the job: the object gets transfered and the original array, emptied.
import 'dart:convert';
var list = Utf8.encode('xxx');
var data = list is Uint8List ? list.buffer : new Uint8List.fromList(list).buffer;
to send the data using window.PostMessage use
window.postMessage({'data': data}, '*', [data]);
and read it on the receiver side like
var string = Utf8.decode(message.data['data']);
See also http://dartbug.com/19968 for the status of transferrables.
The recent Dart dev channel release already ships with Dartium 38.xxx as far as I know.
Here is a small test case for transferrables https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/tests/html/transferables_test.dart

EventSource Error with Dart

I'am trying to use EventSource with Dart.
var source = new EventSource('/myUrl');
source.on.error.add((Event e) => print('error'));
source.on.message.add((MessageEvent me) => print(me.data));
The messages are well received, but 'error' is always print.
How can I got more information about this error ?
I tryied to use ErrorEvent instead of Event but it fail because this event is not a ErrorEvent
I don't have an event source to test with, but I can help you answer your question, "How can I got more information about this error?"
Change:
source.on.error.add((Event e) => print('error'));
To:
source.on.error.add((e) {
print('error');
});
Then, set a breakpoint on the line with print. This will let you inspect the local variable e when you debug your application in Dartium.
You can also use dart2js to compile the application to JavaScript and the Chrome's JavaScript debugger to learn more about e. Search for "error" in the generated JavaScript in the debugger to figure out where to put the breakpoint.
Another trick that is sometimes helpful is to change the code to:
source.on.error.add((int e) => print('error'));
e is not an int, so DartEditor will give you a warning, telling you what type e really is. Then, you can use that type. Next, Command-click on that type to look at the source code for it.
My best advice is to try to use Chrome's JavaScript debugger and debug the problem from there. That's helped me isolate this sort of problem in the past.

having problem in blackberry

I am doing coding from beggining blackberry by Anthony Rizk.
I am stuck with this code as it is showing error again and again...
private void getURL() {
HttpRequestDispatcher dispatcher = new HttpRequestDispatcher(urlField.getText(),
"GET", this);
dispatcher.start();
}
Can anyone explain me why we are passing this as parameter and why actually this code is doing...
"this" refers to the main screen you passed to the class so you can alert the requestFailed string. Check the run method on page 170. You'll see screen.requestFailed("Unexpected...").
As for your error - I suggest adding this line:
System.out.println(" ----------------- HTTPREQUESTDISPATCHER ---------- " + urlField.getText());
right before your dispatcher.start(); line and then compile in debug mode to see what your console says. Just to make sure your URL to request is a valid web URL.
Additionally, make sure your simulator has MDS enabled. You need that to make web calls.
In eclipse it is under Run->run configurations-> simulator tab -> general -> checkbox for Mobile Data System.
I don't know where it is in the RIM package. If you're not using eclipse, you might want to switch over to it. It will highlight errors and try to help you resolve them.

Resources