颤振:有没有办法在颤振中更改 SearchDelegate 搜索栏的高度

时间:2021-02-10 18:53:47

标签: flutter flutter-layout

我正在 Flutter 中做一个应用程序,在我的整个应用程序中,我使用自定义高度的自定义 AppBar (My project AppBar),但我需要在其中创建一个搜索功能,我正在使用 SearchDelegate已经有一个可自定义的 SearchBar (Flutter SearchBar),但我找不到一种方法来自定义它的高度而不更改它的颤振代码。

这是我的 SearchDelegate 代码。

class ProjectSearch extends SearchDelegate {
  @override
  get searchFieldStyle => TextStyle();

  @override
  get searchFieldLabel => 'Pesquisar';

  @override
  List<Widget> buildActions(BuildContext context) {
    return [
      IconButton(
        icon: Icon(
          Icons.clear,
          size: 24.h,
        ), 
        onPressed: () {
          query = '';
        }
      ),
    ];
  }

  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
      icon: AnimatedIcon(
        icon: AnimatedIcons.menu_arrow,
        progress: transitionAnimation,
      ),
      onPressed: () {
        close(context, null);
      }
    );
  }

  @override
  // ignore: missing_return
  Widget buildResults(BuildContext context) {
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    return FutureBuilder(
      future: ProjectsRepository().fetchAllProjects(),
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        List<Project> projects = List<Project>();
        if (snapshot.hasData) {
          projects = snapshot.data;
        } else {
          return Center(
            child:CircularProgressIndicator(
              valueColor: AlwaysStoppedAnimation(Theme.of(context).colorScheme.secondary),
            )
          );
        }

        projects = projects.where((p) => p.name.toLowerCase().startsWith(query.toLowerCase())).toList();

        return ListView.builder(
          itemBuilder: (context, index) => ListTile(
            leading: Icon(Icons.location_city_outlined),
            title: RichText(
              text: TextSpan(
                text: projects[index].name.substring(0, query.length),
                style: TextStyle(
                  color: Colors.black,
                  fontWeight: FontWeight.bold
                ),
                children: [
                  TextSpan(
                    text: projects[index].name.substring(query.length),
                    style: TextStyle(
                      color: Colors.grey,
                    )
                  )
                ]
              )
            ),
            onTap: () async {
              
            },
          ),
          itemCount: projects.length,
        );
      
      });
  }
}

0 个答案:

没有答案