Skip to content

Instantly share code, notes, and snippets.

@shan-shaji
Created November 20, 2020 04:05
Show Gist options
  • Save shan-shaji/0986abdc6a4a90ea99a55c77216fd3b0 to your computer and use it in GitHub Desktop.
Save shan-shaji/0986abdc6a4a90ea99a55c77216fd3b0 to your computer and use it in GitHub Desktop.
import 'dart:convert';
void main() {
String object = '{"name": "hello"}';
print(User.createInstance(jsonDecode(object)).name);
String name = null;
print(name);
}
class User{
String name;
String password;
User({this.name, this.password});
factory User.convertFromJson(Map<String, dynamic> jsonData){
return User(
name: jsonData['name'],
);
}
static User createInstance(Map<String, dynamic> jsonData){
User user = new User(name: jsonData['name']);
return user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment