feat(为搜索列表加入icon)

This commit is contained in:
sanfan.hx
2019-01-20 17:24:59 +08:00
parent 346036cdb9
commit da964ef603
2 changed files with 7 additions and 4 deletions

View File

@ -18,13 +18,14 @@ class MaterialSearchResult<T> extends StatelessWidget {
this.onTap this.onTap
}) : super(key: key); }) : super(key: key);
final T value; final String value;
final VoidCallback onTap; final VoidCallback onTap;
final String text; final String text;
final IconData icon; final IconData icon;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new InkWell( return new InkWell(
onTap: this.onTap, onTap: this.onTap,
child: new Container( child: new Container(
@ -32,8 +33,8 @@ class MaterialSearchResult<T> extends StatelessWidget {
padding: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 10.0), padding: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 10.0),
child: new Row( child: new Row(
children: <Widget>[ children: <Widget>[
new Container(width: 30.0, child: new Icon(icon)) ?? null, new Container(width: 30.0, margin: EdgeInsets.only(right: 10), child: new Icon(icon)) ?? null,
new Expanded(child: new Text(text, style: Theme.of(context).textTheme.subhead)), new Expanded(child: new Text(value, style: Theme.of(context).textTheme.subhead)),
new Text(text, style: Theme.of(context).textTheme.subhead) new Text(text, style: Theme.of(context).textTheme.subhead)
], ],
), ),

View File

@ -21,6 +21,7 @@ import '../common/provider.dart';
import '../model/widget.dart'; import '../model/widget.dart';
import '../widgets/index.dart'; import '../widgets/index.dart';
import 'package:flutter_go/components/search_input.dart'; import 'package:flutter_go/components/search_input.dart';
import '../common/widget_name_to_icon.dart';
const int ThemeColor = 0xFFC91B3A; const int ThemeColor = 0xFFC91B3A;
@ -90,7 +91,8 @@ class _MyHomePageState extends State<AppPage>
return list return list
.map((item) => new MaterialSearchResult<String>( .map((item) => new MaterialSearchResult<String>(
value: item.name, value: item.name,
text: item.name, icon: WidgetName2Icon.icons[item.name] ?? null,
text: 'widget',
onTap: () { onTap: () {
onWidgetTap(item, context); onWidgetTap(item, context);
}, },