In Nylo you can save data to the users device using the NyStorage class.

This uses the flutter_secure_storage package to save and retrieve data.

Store values

To store values, you can use the below helper.

import 'package:nylo_support/helpers/helper.dart';
..."", "10");

Retrieve values

To retrieve values, you can use the below helper.

import 'package:nylo_support/helpers/helper.dart';

// Default
String coins = await""); // 10

// String
String coins = await<String>(""); // 10

// Integer
int coins = await<int>(""); // 10

// double
double coins = await<double>(""); // 10.00

Introduction to storable models

Storable models are useful for storing small sized data to the users devices. It can be helpful way to store the users progress in a game, coins or even their api token.

Here's a model that extends the Storable class.

class User extends Storable {
  String token;
  String username;
  String favouriteCity; 

  User({this.token, this.username, this.favouriteCity});

  toStorage() => {
      "token": this.token, 
      "username": this.username, 
      "favourite_city": this.favouriteCity

  fromStorage(dynamic data) {
    this.token = data['token'];
    this.username = data['username'];
    this.favouriteCity = data['favourite_city'];

After extending the Storable class, you then need to override the toStorage() and fromStorage methods.

  • toStorage() - Creates the payload to be stored.

  • fromStorage(dynamic data) - This will create the model from the data payload, the keys should match the toStorage() method.

Saving a Storable model

To save a Storable model, you can use the below helper.

import 'package:nylo_support/helpers/helper.dart';

User user = new User();
user.username = "Anthony";

String key = "";

// saves to storage;

// or, user);

Retrieve a Storable model

To retrieve a Storable model, you can use the below helper.

import 'package:nylo_support/helpers/helper.dart';
String key = "";

User user = await, model: new User());
print(user.username); // Anthony