PathProvider 插件提供了一种平台透明的方式来访问设备文件系统上的常用位置。该类当前支持访问两个文件系统位置:
一旦你的Flutter应用程序有一个文件位置的引用,你可以使用dart:ioAPI来执行对文件系统的读/写操作。有关使用Dart处理文件和目录的更多信息,请参阅此概述 和这些示例。
以下示例展示了如何统计应用程序中按钮被点击的次数(关闭重启数据不丢失):
import 'dart:io';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
void main() {
runApp(
new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(primarySwatch: Colors.blue),
home: new FlutterDemo(),
),
);
}
class FlutterDemo extends StatefulWidget {
FlutterDemo({Key key}) : super(key: key);
@override
_FlutterDemoState createState() => new _FlutterDemoState();
}
class _FlutterDemoState extends State<FlutterDemo> {
int _counter;
@override
void initState() {
super.initState();
_readCounter().then((int value) {
setState(() {
_counter = value;
});
});
}
Future<File> _getLocalFile() async {
// get the path to the document directory.
String dir = (await getApplicationDocumentsDirectory()).path;
return new File('$dir/counter.txt');
}
Future<int> _readCounter() async {
try {
File file = await _getLocalFile();
// read the variable as a string from the file.
String contents = await file.readAsString();
return int.parse(contents);
} on FileSystemException {
return 0;
}
}
Future<Null> _incrementCounter() async {
setState(() {
_counter++;
});
// write the variable as a string to the file
await (await _getLocalFile()).writeAsString('$_counter');
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text('Flutter Demo')),
body: new Center(
child: new Text('Button tapped $_counter time${
_counter == 1 ? '' : 's'
}.'),
),
floatingActionButton: new FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: new Icon(Icons.add),
),
);
}
}
H5正常但App异常的可能性css异常:不支持的选择器 非H5端不支持*选择器;body的元素选择器请改为page,同样,div和ul和li等改为v...
uni-app选型评估23问如果你关心竞品对比,这里有几份详尽对比:多端开发框架对比横评,参考:https://juejin.im/post/5ca1736af2...
jQuery Mobile CSS 类 jQuery CSS 类 jQuery Mobile CSS 类来设置不同元素的样式。 以下列表包含了通用的 CSS 样式:全局类 以下...
Android 架构Android 操作系统是一个软件组件的栈,在架构图中它大致可以分为五个部分和四个主要层。Linux内核在所有层的最底下...
附录 A安装 Storm 客户端Storm 客户端能让我们使用命令管理集群中的拓扑。按照以下步骤安装 Storm 客户端:从 Storm 站点下载最...
Neo4j CQL MATCH 命令用于从数据库获取有关节点和属性的数据从数据库获取有关节点,关系和属性的数据 MATCH 命令语法: MATCH ( ...