飘扬24小时后如何删除SharedPreferences?

时间:2019-07-08 09:52:34

标签: flutter dart sharedpreferences

我想每隔24小时删除一次SharedPreferences,即使应用程序关闭也是如此。 这是SharedPreferences:

int _counter = 0;

  @override
  void initState() {
    super.initState();
    _loadCounter();
  }

  //Loading counter value on start
  _loadCounter() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {
      _counter = (prefs.getInt('counter') ?? 0);
    });
  }

  //Incrementing counter after click
  _incrementCounter() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {
      _counter +=  n;
      prefs.setInt('counter', _counter);
    });
  }
 _remove() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {

    prefs.remove('counter');
    });
  }

感谢您的帮助!

0 个答案:

没有答案