forked from alibaba/flutter-go
-
Notifications
You must be signed in to change notification settings - Fork 0
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
133 changed files
with
774 additions
and
694 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
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,102 @@ | ||
// | ||
// Created with Android Studio. | ||
// User: 三帆 | ||
// Date: 18/02/2019 | ||
// Time: 14:19 | ||
// email: [email protected] | ||
// tartget: xxx | ||
// | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_go/utils/shared_preferences.dart'; | ||
import 'dart:convert'; | ||
|
||
class SearchHistory { | ||
final String name; | ||
final String targetRouter; | ||
|
||
SearchHistory({@required this.name, @required this.targetRouter}); | ||
} | ||
|
||
class SearchHistoryList { | ||
static SpUtil _sp; | ||
static SearchHistoryList _instance; | ||
static List<SearchHistory> _searchHistoryList = []; | ||
|
||
static SearchHistoryList _getInstance(SpUtil sp) { | ||
// print("SearchHistoryList _getInstance ${_searchHistoryList} ${_instance==null}"); | ||
if (_instance == null) { | ||
_sp = sp; | ||
String json = sp.get(SharedPreferencesKeys.searchHistory); | ||
_instance = new SearchHistoryList.fromJSON(json); | ||
} | ||
return _instance; | ||
} | ||
|
||
factory SearchHistoryList([SpUtil sp]) { | ||
if (sp == null && _instance == null) { | ||
print(new ArgumentError( | ||
['SearchHistoryList need instantiatied SpUtil at first timte '])); | ||
} | ||
return _getInstance(sp); | ||
} | ||
|
||
// List<SearchHistory> _searchHistoryList = []; | ||
|
||
// 存放的最大数量 | ||
int _count = 10; | ||
|
||
SearchHistoryList.fromJSON(String jsonData) { | ||
_searchHistoryList = []; | ||
if (jsonData == null) { | ||
|
||
return; | ||
} | ||
List jsonList = json.decode(jsonData); | ||
jsonList.forEach((value) { | ||
_searchHistoryList.add(SearchHistory( | ||
name: value['name'], targetRouter: value['targetRouter'])); | ||
}); | ||
} | ||
|
||
List<SearchHistory> getList() { | ||
return _searchHistoryList; | ||
} | ||
|
||
clear() { | ||
_sp.remove(SharedPreferencesKeys.searchHistory); | ||
_searchHistoryList = []; | ||
} | ||
|
||
save() { | ||
_sp.putString(SharedPreferencesKeys.searchHistory, this.toJson()); | ||
} | ||
|
||
add(SearchHistory item) { | ||
print("_searchHistoryList> ${_searchHistoryList.length}"); | ||
for (SearchHistory value in _searchHistoryList) { | ||
if (value.name == item.name) { | ||
return ; | ||
} | ||
} | ||
if (_searchHistoryList.length > _count) { | ||
_searchHistoryList.removeAt(0); | ||
} | ||
_searchHistoryList.add(item); | ||
save(); | ||
} | ||
|
||
toJson() { | ||
List<Map<String, String>> jsonList = []; | ||
_searchHistoryList.forEach((SearchHistory value) { | ||
jsonList.add({'name': value.name, 'targetRouter': value.targetRouter}); | ||
}); | ||
return json.encode(jsonList); | ||
} | ||
|
||
@override | ||
String toString() { | ||
// TODO: implement toString | ||
return this.toJson(); | ||
} | ||
} |
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,9 +1,12 @@ | ||
/// Created with Android Studio. | ||
/// User: 三帆 | ||
/// Date: 31/01/2019 | ||
/// Time: 18:13 | ||
/// email: [email protected] | ||
/// target: xxx | ||
|
||
// Created with Android Studio. | ||
// User: 三帆 | ||
// Date: 31/01/2019 | ||
// Time: 18:13 | ||
// email: [email protected] | ||
// target: xxx | ||
// | ||
|
||
|
||
//enum DateType { | ||
// Int, | ||
|
@@ -20,9 +23,16 @@ | |
// spKey({this.name, this.type}); | ||
//} | ||
|
||
class sharedPreferencesKeys { | ||
class SharedPreferencesKeys { | ||
/// boolean | ||
/// 用于欢迎页面. 只有第一次访问才会显示. 或者手动将这个值设为false | ||
static String showWelcome = 'loginWelcone'; | ||
/// json | ||
/// 用于存放搜索页的搜索数据. | ||
/// [{ | ||
/// name: 'name' | ||
/// | ||
/// }] | ||
static String searchHistory = 'searchHistory'; | ||
} | ||
|
Oops, something went wrong.