1、临时解决widget搜索,textField服务端返回路径与本地有误导致的无法跳转的问题

2、添加widget搜索记录清除按钮
This commit is contained in:
zxx
2019-09-17 00:51:17 +08:00
parent 47e4be0b94
commit 594f990d1b
2 changed files with 76 additions and 50 deletions

View File

@ -15,13 +15,9 @@ typedef void OnSubmit(String value);
///搜索结果内容显示面板
class MaterialSearchResult<T> extends StatelessWidget {
const MaterialSearchResult({
Key key,
this.value,
this.text,
this.icon,
this.onTap
}) : super(key: key);
const MaterialSearchResult(
{Key key, this.value, this.text, this.icon, this.onTap})
: super(key: key);
final String value;
final VoidCallback onTap;
@ -30,7 +26,6 @@ class MaterialSearchResult<T> extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new InkWell(
onTap: this.onTap,
child: new Container(
@ -38,8 +33,14 @@ class MaterialSearchResult<T> extends StatelessWidget {
padding: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 10.0),
child: new Row(
children: <Widget>[
new Container(width: 30.0, margin: EdgeInsets.only(right: 10), child: new Icon(icon)) ?? null,
new Expanded(child: new Text(value, style: Theme.of(context).textTheme.subhead)),
new Container(
width: 30.0,
margin: EdgeInsets.only(right: 10),
child: new Icon(icon)) ??
null,
new Expanded(
child: new Text(value,
style: Theme.of(context).textTheme.subhead)),
new Text(text, style: Theme.of(context).textTheme.subhead)
],
),
@ -124,6 +125,7 @@ class _MaterialSearchState<T> extends State<MaterialSearch> {
}
Timer _resultsTimer;
Future _getResultsDebounced() async {
if (_results.length == 0) {
setState(() {
@ -164,6 +166,7 @@ class _MaterialSearchState<T> extends State<MaterialSearch> {
super.dispose();
_resultsTimer?.cancel();
}
Widget buildBody(List results) {
if (_criteria.isEmpty) {
return History();
@ -171,16 +174,11 @@ class _MaterialSearchState<T> extends State<MaterialSearch> {
return new Center(
child: new Padding(
padding: const EdgeInsets.only(top: 50.0),
child: new CircularProgressIndicator()
)
);
child: new CircularProgressIndicator()));
}
if (results.isNotEmpty) {
var content = new SingleChildScrollView(
child: new Column(
children: results
)
);
var content =
new SingleChildScrollView(child: new Column(children: results));
return content;
}
return Center(child: Text("暂无数据"));
@ -241,7 +239,7 @@ class _MaterialSearchState<T> extends State<MaterialSearch> {
],
),
body: buildBody(results),
);
);
}
}
@ -405,34 +403,35 @@ class SearchInput extends StatelessWidget {
}
// wigdet干掉.=> componets
class History extends StatefulWidget {
const History() : super();
@override
_History createState() => _History();
_History createState() => _History();
}
// AppBar 默认的实例,有状态
class _History extends State<History> {
SearchHistoryList searchHistoryList = new SearchHistoryList();
bool refreshFlag;
@override
void initState() {
super.initState();
this.refreshFlag = true;
}
@override
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(
@ -445,20 +444,28 @@ class _History extends State<History> {
}
String targetRouter = value.targetRouter;
list.add(
InkWell(
onTap: () {
Application.router.navigateTo(context, "${targetRouter.toLowerCase()}", transition: TransitionType.inFromRight);
},
child: Chip(
avatar: icon,
label: Text("${value.name}"),
),
)
);
list.add(InkWell(
onTap: () {
Application.router.navigateTo(
context, "${targetRouter.toLowerCase()}",
transition: TransitionType.inFromRight);
},
child: Chip(
avatar: icon,
label: Text("${value.name}"),
),
));
});
return list;
}
_clearHistory() {
searchHistoryList.clear();
this.setState(() {
this.refreshFlag = !this.refreshFlag;
});
}
@override
Widget build(BuildContext context) {
List<Widget> childList = buildChips(context);
@ -470,25 +477,38 @@ class _History extends State<History> {
return Column(
children: <Widget>[
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.fromLTRB(12.0, 12, 12, 0),
child: InkWell(
onLongPress: () {
searchHistoryList.clear();
},
child: Text('历史搜索'),
),
),
alignment: Alignment.centerLeft,
padding: EdgeInsets.fromLTRB(12.0, 12, 12, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
InkWell(
onLongPress: () {
searchHistoryList.clear();
},
child: Text('历史搜索'),
),
GestureDetector(
onTap: _clearHistory,
child: Container(
child: new Icon(Icons.delete,
size: 24.0, color: Theme.of(context).accentColor),
width: 30,
height: 30,
),
)
],
)),
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
),
spacing: 6.0, // gap between adjacent chips
runSpacing: 0.0, // gap between lines
children: childList),
)
],
);
}
}
}

View File

@ -24,6 +24,8 @@ import 'package:flutter_go/components/search_input.dart';
import 'package:flutter_go/model/search_history.dart';
import 'package:flutter_go/resources/widget_name_to_icon.dart';
import 'package:flutter_go/model/user_info.dart';
// 临时修复引入
import '../widgets/elements/Form/Input/TextField/index.dart' as TextField;
class AppPage extends StatefulWidget {
final UserInformation userInfo;
@ -96,10 +98,14 @@ class _MyHomePageState extends State<AppPage>
void onWidgetTap(WidgetPoint widgetPoint, BuildContext context) {
String targetName = widgetPoint.name;
searchHistoryList.add(
SearchHistory(name: targetName, targetRouter: widgetPoint.routerName));
print("searchHistoryList1 ${searchHistoryList.toString()}");
String targetRouter = widgetPoint.routerName;
// 临时修复TextField路径问题
if(widgetPoint.name == 'TextField'){
targetRouter = TextField.Demo.routeName;
}
searchHistoryList.add(
SearchHistory(name: targetName, targetRouter: targetRouter));
print("searchHistoryList1 ${searchHistoryList.toString()}");
Application.router.navigateTo(context, targetRouter.toLowerCase(),
transition: TransitionType.inFromRight);
}