Created
April 5, 2020 12:06
-
-
Save GursheeshSingh/5c2e2c8cd7273bd10177764b510b586b 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
SharedPreferences sharedPreferences; | |
@override | |
void initState() { | |
super.initState(); | |
loadImages(); | |
} | |
loadImages() async { | |
sharedPreferences = await SharedPreferences.getInstance(); | |
List<String> photos = sharedPreferences.getStringList("images"); | |
if (photos == null) { | |
return; | |
} | |
int length = photos.length; | |
_galleryItems = List.generate( | |
length, | |
(index) => GalleryItem( | |
isSvg: false, | |
id: Uuid().v1(), | |
resource: photos[index], | |
), | |
); | |
_photos = List.generate( | |
length, | |
(index) => File( | |
photos[index], | |
), | |
); | |
_photosUrls = List.generate( | |
length, | |
(index) => photos[index], | |
); | |
_photosStatus = List.generate( | |
length, | |
(index) => PhotoStatus.LOADED, | |
); | |
_photosSources = List.generate( | |
length, | |
(index) => PhotoSource.NETWORK, | |
); | |
setState(() {}); | |
} | |
//Update save button | |
Container( | |
margin: EdgeInsets.all(16), | |
child: RaisedButton( | |
child: Text('Save'), | |
onPressed: _onSaveClicked, | |
), | |
) | |
//Add listener on save | |
_onSaveClicked() async { | |
try { | |
sharedPreferences = await SharedPreferences.getInstance(); | |
await sharedPreferences.setStringList("images", _photosUrls); | |
print('Successfully saved'); | |
} catch (e) { | |
print('Error saving '); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment