Skip to content

Instantly share code, notes, and snippets.

@Vloz
Vloz / JSON_Encode_Decode.dart
Created April 28, 2014 07:15
Example of use of reviver and toEncodable functions, to encode and decode a JSON with a List of Object in dart
class MyListClass{
String value;
List<MyItemClass> items;
MyListClass(){}
MyListClass.fromRaw(Map value){
value = JSON.decode(value['value']);
items = JSON.decode(value['items'],reviver:(k,v){
@Vloz
Vloz / DateInputFilter.dart
Created April 12, 2014 19:52
Here is a dateinput polymer filter to convert its value to a DateTime.
class DateTimeFromDateInput extends Transformer<String,DateTime>{
String forward(DateTime d){
String s = d.toString();
return s.substring(0,s.lastIndexOf(' '));
}
DateTime reverse(String s) {
try{
return DateTime.parse(s);
}on Exception {
@Vloz
Vloz / validsiret.dart
Last active August 29, 2015 13:59
Methode de validation de code SIRET.Renvoi Faux si la chaine contient des lettres.
static bool validsiret(String siret){
if(siret==null)
return false;
String s = siret.replaceAll(' ','');
if(s.length==0)
return false;
List<int> ln = new List<int>();
for (int i = 0; i < s.length ; i++) {
int n = int.parse(s[i], onError:(_){return 127;});
ln.add(i.isEven ? (n * 2 > 9 ? n * 2 - 9 : n * 2) : n);