[Flutter]SharedPreferences

[Flutter]SharedPreferences

更新於 發佈於 閱讀時間約 2 分鐘

首先需要在pubspec.yaml文件中添加依賴。

宣告

SharedPreferences record = await SharedPreferences.getInstance();


寫入

//字串資料
await record.setString(key, value);

//布林資料
await record.setBool(key, value);

//浮點數資料
await record.setDouble(key, value);

//整數資料
await record.setInt(key, value);

//字串列表資料
await record.setStringList(key, value);


讀取

//字串資料
record.getString(key);

//布林資料
record.getBool(key);

//浮點數資料
record.getDouble(key);

//整數資料
record.getInt(key);

//字串列表資料
record.getStringList(key);


删除

指定

record.remove(key);


全部

record.clear();






avatar-img
小黑與程式的邂逅
8會員
123內容數
嗨,我是一名程式設計師,會在這分享開發與學習紀錄。
留言
avatar-img
留言分享你的想法!
小黑與程式的邂逅 的其他內容
class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Center( child: Table( columnWid
下面代碼為兩列的GridView class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return new GridView.count( cro
可以透過scrollDirection來設定垂直或水平滾動列表資料。 垂直滾動 class HomePage extends StatelessWidget { //列表集合資料 List<Widget> list = <Widget>[ ListTile( ti
這篇使用pubspec.yaml來管理第三方依賴套件。YAML是一種直覺、可讀性高的文件格式;他和xml或Json相比語法簡單且容易解析,所以常用於配置文件。 Flutter預設的設定檔是pubspec.yaml,底下是關鍵字解釋: name:應用程式或套件名稱。 description: 應用
class MyApp extends StatefulWidget { @override myAppState createState() => myAppState(); } class myAppState extends State<MyApp> { //目前選擇頁索引值
class MyApp extends StatelessWidget { final List<Tab> myTabs = <Tab>[ Tab(text: '第一頁'), Tab(text: '第二頁'), Tab(text: '第三頁'), ]; fina
class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Center( child: Table( columnWid
下面代碼為兩列的GridView class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return new GridView.count( cro
可以透過scrollDirection來設定垂直或水平滾動列表資料。 垂直滾動 class HomePage extends StatelessWidget { //列表集合資料 List<Widget> list = <Widget>[ ListTile( ti
這篇使用pubspec.yaml來管理第三方依賴套件。YAML是一種直覺、可讀性高的文件格式;他和xml或Json相比語法簡單且容易解析,所以常用於配置文件。 Flutter預設的設定檔是pubspec.yaml,底下是關鍵字解釋: name:應用程式或套件名稱。 description: 應用
class MyApp extends StatefulWidget { @override myAppState createState() => myAppState(); } class myAppState extends State<MyApp> { //目前選擇頁索引值
class MyApp extends StatelessWidget { final List<Tab> myTabs = <Tab>[ Tab(text: '第一頁'), Tab(text: '第二頁'), Tab(text: '第三頁'), ]; fina