Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo增加组件搜索功能 #410

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading