在Flutter中搜索,显示导航错误

时间:2019-09-14 07:55:51

标签: flutter dart

我正在尝试在flutter应用程序的应用程序栏中实现搜索选项,并向我显示

在不包含导航器的上下文中请求的导航器操作。

我曾尝试使用构建器,但无法正常工作。

这是我的代码


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text(
            'xvy,
          ),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.search),
              onPressed:() {
                showSearch(context: context, delegate: DataSearch());
            },)
          ],
        ),
        )
      );
  }
}

class DataSearch extends SearchDelegate<String>{
  @override
  List<Widget> buildActions(BuildContext context) {
    //actions for app bar
    return [
      IconButton(icon: Icon(Icons.clear), onPressed: () {},)
    ];
  }

  @override
  Widget buildLeading(BuildContext context) {
    // leading icon on the left of the app bar
    return IconButton(
      icon: AnimatedIcon(
        icon: AnimatedIcons.menu_arrow,
        progress: transitionAnimation,
      ),
      onPressed: () {},
    );
  }

  @override
  Widget buildResults(BuildContext context) {
    // show some results based on the selection
    return null;
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    // show when someone searches for something
    return null;
  }
} ```

0 个答案:

没有答案