我想知道如何构建一个搜索栏,在其中将用户搜索输入过滤到组或选项卡中,例如instagram,就像人物,标签,地点一样,但我不知道该怎么做!
答案 0 :(得分:0)
它看起来像这样:
import 'package:flutter/material.dart';
main() => runApp(
MaterialApp(
// home: Scaffold(
// body: Container(child: SearchButton()),
home: Body()),
);
class Body extends StatefulWidget {
@override
_BodyState createState() => _BodyState();
}
class _BodyState extends State<Body> {
TextEditingController controller;
@override
void initState() {
super.initState();
controller = TextEditingController();
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
leading: Icon(Icons.search),
title: TextField(
controller: controller,
cursorColor: Colors.white,
style: TextStyle(color: Colors.white),
),
bottom: TabBar(tabs: [
Tab(icon: Icon(Icons.people)),
Tab(icon: Icon(Icons.location_city)),
]),
),
body: TabBarView(children: [Container(), Container()]),
),
);
}
}