使用localsorage在颤音中节省价值

2022-08-06

以下示例是关于Whatever中包含使用localsorage在颤音中节省价值用法的示例代码,想了解使用localsorage在颤音中节省价值的具体用法?使用localsorage在颤音中节省价值怎么用?使用localsorage在颤音中节省价值使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。

[英]:save value using localsorage in flutter源码类型:Whatever
You can use Localstorage

flutter pub add localstorage

1- Add dependency to pubspec.yaml (Change the version based on the last)

dependencies:
  ...
  localstorage: ^4.0.0+1

2- Then run the following command

flutter packages get

3- import the localstorage :

import 'package:localstorage/localstorage.dart';

4- create an instance

class MainApp extends StatelessWidget {
  final LocalStorage storage = new LocalStorage('localstorage_app');
  ...
}

Add item to lcoalstorage :

void addItemsToLocalStorage() {
  storage.setItem('name', 'Abolfazl');
  storage.setItem('family', 'Roshanzamir');

  final info = json.encode({'name': 'Darush', 'family': 'Roshanzami'});
  storage.setItem('info', info);
}

Get an item from lcoalstorage:

void getitemFromLocalStorage() {
  final name = storage.getItem('name'); // Abolfazl
  final family = storage.getItem('family'); // Roshanzamir
  
  Map<String, dynamic> info = json.decode(storage.getItem('info'));
  final info_name=info['name'];
  final info_family=info['family'];
}

Delete an item from localstorage :

void removeItemFromLocalStorage() {
  storage.deleteItem('name');
  storage.deleteItem('family');
  storage.deleteItem('info');
}

本文地址:https://www.itbaoku.cn/snippets/795590.html