首页 > 解决方案 > TMDB db 从中获取查询 - Flutter

问题描述

我要做的是从 TMDB 数据库(https://developers.themoviedb.org/3)中获取最受欢迎电影的查询。因此,当我按标题名称搜索时,它会显示出来。我创建了一个关于程序外观的查询模板(电影)。我的问题是,如何从 TMDB 获取该查询列表,以便我可以按标题进行搜索。这是我的带有查询模板的代码

代码:

class DataSearch extends SearchDelegate<String> {
  final movies = [
    "film 1",
    "Grmi 2",
    "Movie 3",
    "Test12441",
    "Test1232",
    "Test6612",
    "aaaaaaaaaaa"
  ];

  final recent = [
    "film 1",
    "Grmi 2",
    "Test6612",
  ];

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

  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
        icon: Icon(Icons.arrow_back),
        onPressed: () {
          close(context, null);
        });
  }

  @override
  Widget buildResults(BuildContext context) {
    //nesta
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    final suggesstionList = query.isEmpty
        ? recent
        : movies.where((p) => p.startsWith(query)).toList();

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

任何帮助都会很棒。提前致谢

标签: flutterdartsearch

解决方案


推荐阅读