Why does import 'dart:convert' show BASE64; give me an error?
import 'dart:convert' show BASE64;
var output = BASE64.encode(digest.bytes)
Undefined name 'BASE64'.
Thanks
In Dart 2 such SCREAMING_CASE constant names were changed to lowerCamelCase
Just change BASE64 to base64. Similar with JSON -> json and a few more.
Related
in vs code, i am getting this error in the basic input taking code from the user
my complete code:
import 'dart:io';
void main(){
stdout.write("Enter your name : ");
var name = stdin.readLineSync();
stdout.write(name);
}
Error in the compiler:
playground.dart:9:23: Error: Method not found: 'Stdin.readLineSync'.
String name = Stdin.readLineSync();
^^^^^^^^^^^^
You must add:
import 'dart:io';
before your main function
To learn dart as console application you should use IntelliJ IDEA IDE.
This is the best IDE for dart.
vscode, dartpad does not support stdin stdout.
if you were getting error like
"Getter not found.'stdin'"
in VSCode check for the extension "dart" is installed on your VSCode then checkitout for run i.e dart run command
stdin.readLineSync()!
use the '!' as I did below:
void main(){
stdout.write("Enter your name : ");
var name = stdin.readLineSync()!;
stdout.write(name);
}
The error you get with stdin.readLineSync() is due to null safety introduced in Dart 2.12. Just add (!)
var name = stdin.readLineSync()!;
you should write it -> stdout.writeln and also import the library for it, I amended the code for you below, and it works fine on VSCode
import 'dart:io';
void main(){
stdout.writeln("Enter your name : ");
var name = stdin.readLineSync();
stdout.write(name);
}
I have a json stored as string like below
String json="[{"name":"a","id",1},{"name":"b","id",2},{"name":"c","id",3}]";
My Question how to encode this to a map or a list to get access to the keys and use the values?
You need to JSON-decode the value first
import 'dart:convert';
final decoded = jsonDecode(json);
print(decoded[0]['name']); // just one example
I have this code method in a java class with JAX-RS:
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
#Path("/reports/{id: (zerotrips|notrips|tripsummary|rejectedtrips){1}/{0,1}}")
#GET
public Response get(#Context HttpServletRequest aRequest){
....
}
Could someone give some examples of the url mapped by the expression in the #Path annotation?
/reports/zerotrips
/reports/zerotrips/
Replace zerotrips with any of the other ones on between the parenthesis
(zerotrips|notrips|tripsummary|rejectedtrips){1}
This says any one of the values in the parenthesis. | means "or". The {1} means "once".
/{0,1}
means with or without a slash. {0,1} means zero to once.
A pattern followed by {} gives the number of times it is allowed. For example a{3,5} means an a three to five times. So the following would match: aaa, aaaa, aaaaa, but aa would not match.
I am trying to use a NumericProperty but getting Type errors when trying to use it as a value
My code looks like this
from kivy.properties import NumericProperty
from kivy.uix.widget import Widget
class Segment(Widget):
def __init__(self, segments):
super(Segment, self).__init__()
self.segments = NumericPropery(segments)
def build(self):
for i in range(0, self.segments):
# Do something
I get an error :
for i in range(0, self.segments):
TypeError: range() integer end argument expected, got kivy.properties.NumericProperty.
so I tried using self.segments.get() instead, but then I got this error
TypeError: get() takes exactly one argument (0 given)
apperently the get function expects <kivy._event.EventDispatcher> object argument
Any idea how to get around this?
I had a similar problem with this code ...
class GameModel(object):
some_number = NumericProperty(1)
def __init__(self):
self.some_number = 2
... which raised the error:
TypeError: Argument 'obj' has incorrect type (expected kivy._event.EventDispatcher, got GameModel)
I did declare the property at class level though. In my case the problem was that the class itself was not derived from a Kivy Widget class or - as stated in the error message - from an EventDispatcher Object
Deriving from EventDispatcher fixed my problem:
class GameModel(EventDispatcher):
Hope this is helpful for someone else some day ;-)
You have to declare properties at class level.
class Segment(Widget):
segments = NumericProperty()
This will give the correct behaviour. The problem is that properties do their own management of per-instance values and interacting with the eventloop etc.. If you don't declare them at class level, they don't get to do this, so your functions only see the NumericProperty itself (which is your problem).
I am creating a scientific calc app in DART . i dont knw how to use trignometric functions like sine , cosine . i used "math.sin()" , but it throws an exception "NO top-level getter math.get declared " how to solve it ? thanks in advance
To use trigonometric functions in Dart, import the dart:math library. For example:
import 'dart:math';
main() {
print(sin(pi));
}
If you want, you can import with a prefix to avoid namespace collisions:
import 'dart:math' as Math;
main() {
print(Math.sin(Math.pi));
}