Created
October 20, 2019 03:46
-
-
Save mh-mobile/58fefc723fc1bce5b97ce9a75c7a2030 to your computer and use it in GitHub Desktop.
SharedPreferencesで文字列配列の取得・設定例
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
getMessages() async { | |
SharedPreferences prefs = await SharedPreferences.getInstance(); | |
List<String> messages = await prefs.getStringList("messages") ?? List<String>(); | |
setState(() { | |
_messages = messages.map((message) { | |
return Message(message: message,); | |
}).toList() ; | |
}); | |
} | |
saveMessages() async { | |
SharedPreferences prefs = await SharedPreferences.getInstance(); | |
List<String> messages = _messages.map((message) { | |
return message.message; | |
}).toList(); | |
await prefs.setStringList("messages", messages); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment