Skip to content

Flutter存储插件:用法和shared_preferences完全一样;不同于shared_preferences,本插件并没有使用默认的存储空间,防止默认的存储空间太过庞大。

License

Notifications You must be signed in to change notification settings

Yingzi-Technology/yingzi_flutter_shared_preferences

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YZ Shared preferences plugin

A plugin modified basing on shared_preferences

User the special NSUserDefaults on iOS and macOS, SharedPreferences on Android instead of default. 不同于 shared_preferences,本插件并没有使用默认的存储空间,防止默认的存储空间因为共用的原因太过庞大。

Usage

To use this plugin, add yshared_preferences as a dependency in your pubspec.yaml file.

Example

import 'package:flutter/material.dart';
import 'package:yshared_preferences/shared_preferences.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
      child: RaisedButton(
        onPressed: _incrementCounter,
        child: Text('Increment Counter'),
        ),
      ),
    ),
  ));
}

_incrementCounter() async {
  YSharedPreferences prefs = await YSharedPreferences.getInstance();
  int counter = (prefs.getInt('counter') ?? 0) + 1;
  print('Pressed $counter times.');
  await prefs.setInt('counter', counter);
}

Testing

You can populate YSharedPreferences with initial values in your tests by running this code:

YSharedPreferences.setMockInitialValues (Map<String, dynamic> values);

About

Flutter存储插件:用法和shared_preferences完全一样;不同于shared_preferences,本插件并没有使用默认的存储空间,防止默认的存储空间太过庞大。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published