Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DeckeDeng committed Feb 19, 2019
2 parents 47116f1 + 59253b7 commit 2996300
Show file tree
Hide file tree
Showing 133 changed files with 774 additions and 694 deletions.
27 changes: 7 additions & 20 deletions lib/components/list_refresh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ class _ListRefreshState extends State<ListRefresh> {
});
}

/*
* 回弹效果
* */
// 回弹效果
backElasticEffect() {
// double edge = 50.0;
// double offsetFromBottom = _scrollController.position.maxScrollExtent - _scrollController.position.pixels;
Expand All @@ -55,9 +53,7 @@ class _ListRefreshState extends State<ListRefresh> {
// }
}

/*
* list探底,执行的具体事件
* */
// list探底,执行的具体事件
Future _getMoreData() async {
if (!isLoading && _hasMore) {
// 如果上一次异步请求数据完成 同时有数据可以加载
Expand All @@ -82,9 +78,7 @@ class _ListRefreshState extends State<ListRefresh> {
}
}

/*
* 伪装吐出新数据
* */
// 伪装吐出新数据
Future<List> mokeHttpRequest() async {
if (widget.requestApi is Function) {
final listObj = await widget.requestApi({'pageIndex': _pageIndex});
Expand All @@ -97,11 +91,8 @@ class _ListRefreshState extends State<ListRefresh> {
});
}
}

/*
* 下拉加载的事件,清空之前list内容,取前X个
* 其实就是列表重置
* */
// 下拉加载的事件,清空之前list内容,取前X个
// 其实就是列表重置
Future<Null> _handleRefresh() async {
List newEntries = await mokeHttpRequest();
if (this.mounted) {
Expand All @@ -115,9 +106,7 @@ class _ListRefreshState extends State<ListRefresh> {
}
}

/*
* 加载中的提示
* */
// 加载中的提示
Widget _buildLoadText() {
return Container(
child: Padding(
Expand All @@ -128,9 +117,7 @@ class _ListRefreshState extends State<ListRefresh> {
));
}

/*
* 上提加载loading的widget,如果数据到达极限,显示没有更多
* */
// 上提加载loading的widget,如果数据到达极限,显示没有更多
Widget _buildProgressIndicator() {
if (_hasMore) {
return new Padding(
Expand Down
71 changes: 65 additions & 6 deletions lib/components/search_input.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:fluro/fluro.dart';
import 'package:meta/meta.dart';
import 'package:flutter_go/resources/widget_name_to_icon.dart';
import 'package:flutter_go/routers/application.dart';
import '../model/search_history.dart';

typedef String FormFieldFormatter<T>(T v);
typedef bool MaterialSearchFilter<T>(T v, String c);
Expand Down Expand Up @@ -409,11 +413,9 @@ class History extends StatefulWidget {
_History createState() => _History();
}

/*
* AppBar 默认的实例,有状态
* */
// AppBar 默认的实例,有状态
class _History extends State<History> {

SearchHistoryList searchHistoryList = new SearchHistoryList();

@override
void initState() {
Expand All @@ -424,11 +426,68 @@ class _History extends State<History> {
void dispose() {
super.dispose();
}
buildChips(BuildContext context) {
List<Widget> list = [];
List<SearchHistory> historyList = searchHistoryList.getList();
print("historyList> $historyList");
Color bgColor = Theme.of(context).primaryColor;
historyList.forEach((SearchHistory value) {

Widget icon = CircleAvatar(
backgroundColor: bgColor,
child: Text(
value.name.substring(0, 1),
style: TextStyle(color: Colors.white),
),
);
if (WidgetName2Icon.icons[value.name] != null) {
icon = Icon(WidgetName2Icon.icons[value.name], size: 25);
}

list.add(
InkWell(
onTap: () {
Application.router.navigateTo(context, "${value.targetRouter}", transition: TransitionType.inFromRight);
},
child: Chip(
avatar: icon,
label: Text("${value.name}"),
),
)
);
});
return list;
}
@override
Widget build(BuildContext context) {
return new Center(
child: Text('这是一个即将完善的历史记录的面板'),
List<Widget> childList = buildChips(context);
if (childList.length == 0) {
return Center(
child: Text("当前历史面板为空"),
);
}
return Column(
children: <Widget>[
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.fromLTRB(12.0, 12, 12, 0),
child: InkWell(
onLongPress: () {
searchHistoryList.clear();
},
child: Text('历史搜索'),
),
),
Container(
padding: EdgeInsets.only(left: 10),
alignment: Alignment.topLeft,
child: Wrap(
spacing: 6.0, // gap between adjacent chips
runSpacing: 0.0, // gap between lines
children: childList
),
)
],
);
}
}
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'routers/application.dart';
import 'package:flutter_go/utils/provider.dart';
import 'package:flutter_go/utils/shared_preferences.dart';
import 'package:flutter_go/views/first_page/home.dart';
import 'package:flutter_go/model/search_history.dart';
import 'views/welcome_page/index.dart';

const int ThemeColor = 0xFFC91B3A;
Expand All @@ -20,7 +21,7 @@ class MyApp extends StatelessWidget {
Application.router = router;
}
showWelcomePage() {
bool showWelcome = sp.getBool(sharedPreferencesKeys.showWelcome);
bool showWelcome = sp.getBool(SharedPreferencesKeys.showWelcome);
if (showWelcome == null || showWelcome == true) {
return WelcomePage();
} else {
Expand Down Expand Up @@ -58,6 +59,7 @@ void main() async {
final provider = new Provider();
await provider.init(true);
sp = await SpUtil.getInstance();
new SearchHistoryList(sp);
db = Provider.db;
runApp(new MyApp());
}
102 changes: 102 additions & 0 deletions lib/model/search_history.dart
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();
}
}
24 changes: 17 additions & 7 deletions lib/resources/shared_preferences_keys.dart
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,
Expand All @@ -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';
}

Loading

0 comments on commit 2996300

Please sign in to comment.