如何修复Flutter中的“显示在搜索栏下方的内容”?

时间:2019-06-06 08:43:36

标签: search flutter dart searchbar

我想在搜索栏中单击“建议列表”后,而不是在搜索栏中,如下面提供的屏幕截图所示,在全屏中显示结果或内容...

试图跟进无聊的表演,但无法理解他们是如何实现的。?

先谢谢了!

import 'package:flutter/material.dart';
import 'urls_index.dart';
import 'ContentPage.dart';

class DataSearch extends SearchDelegate<String> {
var names = new urlsindexs();

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

@override
Widget buildLeading(BuildContext context) {

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

@override
Widget buildResults(BuildContext context) {

return ContentPage();
}

@override
Widget buildSuggestions(BuildContext context) {
// TODO: implement buildSuggestions
var abc = query.isEmpty
    ? names.websitename
    : names.websitename
        .where((p) => p.toUpperCase().startsWith(query.toUpperCase()))
        .toList();

return ListView.builder(
  itemBuilder: (context, index) => ListTile(
        onTap: () {
          showResults(context);
        },
        title: RichText(
          text: TextSpan(
              text: abc[index].substring(0, query.length),
              style: TextStyle(
                  color: Colors.black54, fontWeight: FontWeight.bold),
              children: [
                TextSpan(
                    text: abc[index].substring(query.length),
                    style: TextStyle(color: Colors.grey))
              ]),
        ),
      ),
  itemCount: abc.length,
);
}
}

获取此信息:https://ibb.co/vYW4G3x 想要实现这一目标:https://ibb.co/pzBpNPK(无搜索栏)

已解决! 我改变了...

import 'package:flutter/material.dart';
import 'urls_index.dart';

class DataSearch extends SearchDelegate<String> {
var names = new urlsindexs();

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

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

@override
Widget buildResults(BuildContext context) {
// TODO: implement buildResults
var abc = query.isEmpty
    ? names.websitename
    : names.websitename
        .where((p) => p.toUpperCase().startsWith(query.toUpperCase()))
        .toList();

return ListView.builder(
  itemBuilder: (context, index) => ListTile(
        onTap: () {
          showResults(context);
        },
        title: RichText(
          text: TextSpan(
              text: abc[index].substring(0, query.length),
              style: TextStyle(
                  color: Colors.black54, fontWeight: FontWeight.bold),
              children: [
                TextSpan(
                    text: abc[index].substring(query.length),
                    style: TextStyle(color: Colors.grey))
              ]),
        ),
      ),
  itemCount: abc.length,
);
}

@override
Widget buildSuggestions(BuildContext context) {
// TODO: implement buildSuggestions
var abc = query.isEmpty
    ? names.websitename
    : names.websitename
        .where((p) => p.toUpperCase().startsWith(query.toUpperCase()))
        .toList();

return ListView.builder(
  itemBuilder: (context, index) => ListTile(
        onTap: () {
          // showResults(context);
          Navigator.of(context).pushNamed("/Store1");
        },
        title: RichText(
          text: TextSpan(
              text: abc[index].substring(0, query.length),
              style: TextStyle(
                  color: Colors.black54, fontWeight: FontWeight.bold),
              children: [
                TextSpan(
                    text: abc[index].substring(query.length),
                    style: TextStyle(color: Colors.grey))
              ]),
        ),
      ),
    itemCount: abc.length,
   );
  }
}

0 个答案:

没有答案