Skip to content

Commit

Permalink
Merge pull request #410 from Tencent/feature/search_component
Browse files Browse the repository at this point in the history
demo增加组件搜索功能
  • Loading branch information
Luozf12345 authored Dec 17, 2024
2 parents 4dd5022 + b3b19ea commit 77bbc0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion tdesign-component/example/lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MyHomePage extends StatefulWidget {

class _MyHomePageState extends State<MyHomePage> {
bool useConch = false;
String searchText = '';

@override
void initState() {
Expand Down Expand Up @@ -108,7 +109,8 @@ class _MyHomePageState extends State<MyHomePage> {
return const web.WebMainBody();
}
return SafeArea(
child: Center(
child: Align(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down Expand Up @@ -160,6 +162,15 @@ class _MyHomePageState extends State<MyHomePage> {
),
));

children.add(TDSearchBar(
placeHolder: '请输入组件名称',
onTextChanged: (value){
setState(() {
searchText = value;
});
},
));

exampleMap.forEach((key, value) {
children.add(Container(
alignment: Alignment.topLeft,
Expand All @@ -174,6 +185,10 @@ class _MyHomePageState extends State<MyHomePage> {
),
));
value.forEach((model) {
if(searchText.isNotEmpty && !model.text.toLowerCase().contains(searchText.toLowerCase())){
// 如果有搜索文案,不再搜索中的组件不展示
return;
}
model.spline = WebMdTool.getSpline(key);
if (model.isTodo) {
if (_kShowTodoComponent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class _TDSearchBarState extends State<TDSearchBar>
maxWidth: box.maxWidth - 51,
),
child: TDText(
widget.placeHolder,
widget.placeHolder ?? '',
font: getSize(context),
textColor: TDTheme.of(context).fontGyColor3,
maxLines: 1,
Expand Down

0 comments on commit 77bbc0a

Please sign in to comment.