From c40401a2deef8f4248b3050f365d088843753530 Mon Sep 17 00:00:00 2001 From: chengww Date: Fri, 29 Mar 2019 11:28:31 +0800 Subject: [PATCH] Add sp_store_util --- lib/pages/home_page.dart | 17 +++-------------- lib/utils/sp_store_util.dart | 13 +++++++++++++ 2 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 lib/utils/sp_store_util.dart diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 4b64786..3029f9e 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -1,8 +1,7 @@ import 'package:flutter/material.dart'; import 'package:one_article/bean/article_bean.dart'; import 'package:one_article/db/database.dart'; -import 'package:shared_preferences/shared_preferences.dart'; - +import 'package:one_article/utils/sp_store_util.dart'; class HomePage extends StatefulWidget { final ArticleBean article; @@ -22,7 +21,7 @@ class _HomePageState extends State { @override Widget build(BuildContext context) { - _getFontSize().then((value) { + getFontSize().then((value) { if (value != _fontSize) { setState(() { _fontSize = value; @@ -106,7 +105,7 @@ class _HomePageState extends State { Expanded( child: Slider( onChanged: (double value) { - _storeFontSize(value.roundToDouble()); + storeFontSize(value.roundToDouble()); mSetState(() => _fontSize = value.roundToDouble()); setState(() {}); }, @@ -135,14 +134,4 @@ class _HomePageState extends State { } -final String fontSizeKey = "fontSize"; - -_storeFontSize(double value) async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setDouble(fontSizeKey, value); -} -Future _getFontSize() async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - return prefs.getDouble(fontSizeKey) ?? 18; -} diff --git a/lib/utils/sp_store_util.dart b/lib/utils/sp_store_util.dart new file mode 100644 index 0000000..e85d131 --- /dev/null +++ b/lib/utils/sp_store_util.dart @@ -0,0 +1,13 @@ +import 'package:shared_preferences/shared_preferences.dart'; + +final String fontSizeKey = "fontSize"; + +storeFontSize(double value) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + prefs.setDouble(fontSizeKey, value); +} + +Future getFontSize() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + return prefs.getDouble(fontSizeKey) ?? 18; +} \ No newline at end of file