【发布时间】:2020-10-02 01:42:57
【问题描述】:
我目前有一个颤振应用程序,它在网格视图中显示可点击的图像。
选择一张图片后,它会将您带到一个详细页面,其中提供有关所选类别的更多信息:
我现在需要构建基于类别详细信息进行过滤的搜索功能。 因此,如果我搜索“钓鱼”,gridview 过滤器会显示“农业”以及包含该词的任何其他类别详细信息。
我目前使用 Firebase 在用户选择类别时返回类别详细信息,因此我假设搜索必须链接到我的 firebase?
我试过在网上寻找答案,但没有一个能满足我的具体要求。
更新 包含的 Gridview 页面代码:
class _LevelPageState extends State<LevelPage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
backgroundColor: Colors.grey,
title: Text(widget.level.data["region"]),
centerTitle: true,
),
body: ListView(shrinkWrap: true, children: <Widget>[
Container(
child: ListTile(
title: Text(
'Current Level ' + widget.level.data["level"].toString(),
style: TextStyle(
color: widget.level.data["level"] == 5
? Colors.red[900]
: widget.level.data["level"] == 4
? Colors.orange[900]
: widget.level.data["level"] == 3
? Colors.brown[300]
: widget.level.data["level"] == 2
? Colors.blue[300]
: widget.level.data["level"] == 1
? Colors.green[300]
: Colors.black,
fontSize: 25,
fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
Container(
height: (MediaQuery.of(context).size.height),
padding: EdgeInsets.all(10),
child: GridView.count(
shrinkWrap: true,
physics: ScrollPhysics(),
mainAxisSpacing: 40,
crossAxisSpacing: 20,
crossAxisCount: 3,
childAspectRatio: MediaQuery.of(context).size.height / 400,
children: <Widget>[
ListTile(
title: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.grey,
),
child: InkWell(
enableFeedback: true,
child: Image.asset('assets/images/mediaicon.png'),
onTap: () => {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CategoryPage(
text1: 'Media',
text2: widget.level.data["region"].toString(),
text3:
widget.level.data["level"].toString())))
},
splashColor: Colors.white,
borderRadius: BorderRadius.circular(20),
)),
subtitle: Text('Media',
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
textAlign: TextAlign.center),
),
ListTile(
title: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.grey,
),
child: InkWell(
enableFeedback: true,
child: Image.asset('assets/images/mobileanditicon.png'),
onTap: () => {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CategoryPage(
text1: 'Info and Comms',
text2: widget.level.data["region"].toString(),
text3:
widget.level.data["level"].toString())))
},
splashColor: Colors.white,
borderRadius: BorderRadius.circular(20),
)),
subtitle: Text('Info and Comms',
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
textAlign: TextAlign.center),
),
ListTile(
title: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.grey,
),
child: InkWell(
enableFeedback: true,
child: Image.asset('assets/images/utilitiesicon.png'),
onTap: () => {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CategoryPage(
text1: 'Utilities',
text2: widget.level.data["region"].toString(),
text3:
widget.level.data["level"].toString())))
},
splashColor: Colors.white,
borderRadius: BorderRadius.circular(20),
)),
subtitle: Text('Utilities',
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
textAlign: TextAlign.center),
),
ListTile(
title: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.grey,
),
child: InkWell(
enableFeedback: true,
child: Image.asset('assets/images/educationicon.png'),
onTap: () => {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CategoryPage(
text1: 'Education',
text2: widget.level.data["region"].toString(),
text3:
widget.level.data["level"].toString())))
},
splashColor: Colors.white,
borderRadius: BorderRadius.circular(20),
)),
subtitle: Text('Education',
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
textAlign: TextAlign.center),
),
ListTile(
title: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.grey,
),
child: InkWell(
enableFeedback: true,
child: Image.asset('assets/images/repairsicon.png'),
onTap: () => {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CategoryPage(
text1: 'Repairs',
text2: widget.level.data["region"].toString(),
text3:
widget.level.data["level"].toString())))
},
splashColor: Colors.white,
borderRadius: BorderRadius.circular(20),
)),
subtitle: Text('Repairs',
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
textAlign: TextAlign.center),
),
ListTile(
title: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.grey,
),
child: InkWell(
enableFeedback: true,
child:
Image.asset('assets/images/domestichelpicon.png'),
onTap: () => {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CategoryPage(
text1: 'Domestic Help',
text2: widget.level.data["region"].toString(),
text3:
widget.level.data["level"].toString())))
},
splashColor: Colors.white,
borderRadius: BorderRadius.circular(20),
)),
subtitle: Text('Domestic Help',
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
textAlign: TextAlign.center),
),
],
),
),
]));
}
}
我已将上述代码调整为仅包含 6 个 gridview 图像以缩短代码。
【问题讨论】:
-
嗨@SagarAcharya,我确实解决了这个问题,但它只根据网格内的内容过滤网格。我还需要搜索该特定类别中的详细信息。
-
我可以很容易地帮助你,但你能先上传你的gridview的代码吗?
-
感谢@AntoninGAVREL - 我已经更新了我的问题以包含 gridview 代码。
标签: firebase flutter search dart gridview