Created
November 20, 2020 04:05
-
-
Save shan-shaji/0986abdc6a4a90ea99a55c77216fd3b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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