-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:nyalcf/model/User.dart'; | ||
import 'package:nyalcf/util/FileIO.dart'; | ||
|
||
class UserInfoStorage { | ||
static final path = FileIO.support_path; | ||
|
||
/** | ||
* 保存数据 | ||
*/ | ||
static Future<void> save(User data) async { | ||
final String write_data = jsonEncode(data); | ||
await File("${await path}/session.json") | ||
.writeAsString(write_data, encoding: utf8); | ||
} | ||
|
||
/** | ||
* 读取数据 | ||
*/ | ||
static Future<User> read() async { | ||
final String result = | ||
await File("${await path}/session.json").readAsString(encoding: utf8); | ||
return User.fromJson(jsonDecode(result)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
import 'package:path_provider/path_provider.dart'; | ||
|
||
class FileIO { | ||
final _support_path = getApplicationSupportDirectory(); | ||
final _cache_path = getApplicationCacheDirectory(); | ||
static final _support_path = getApplicationSupportDirectory(); | ||
static final _cache_path = getApplicationCacheDirectory(); | ||
|
||
Future<String> get cache_path async { | ||
/** | ||
* 获取缓存目录 | ||
*/ | ||
static Future<String> get cache_path async { | ||
String path = ""; | ||
await _cache_path.then((value) => path = value.path); | ||
return path; | ||
} | ||
|
||
/** | ||
* 获取数据存储目录 | ||
*/ | ||
static Future<String> get support_path async { | ||
String path = ""; | ||
await _support_path.then((value) => path = value.path); | ||
return path; | ||
} | ||
} |