从列表导航到联系人

问题描述 投票:1回答:1

所以目前我有一个联系人列表,我可以在静态列表中查看我的联系人。我希望能够点击搜索栏,而不是通过隐藏联系人,模糊用户视图,搜索将在新的空白页面中打开

 class _ContactPage extends State<ContactsPage> {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          home: new Scaffold(
              appBar: new AppBar(
                title: widget.appBarTitle,
flutter flutter-layout
1个回答
0
投票

您可以将Scaffold的主体包裹在导航器中,并在开始键入时将搜索页面推送到该导航器。像这样的东西:

...

// Declare this at the top
_navigatorKey = new GlobalKey<NavigatorState>();

...

// onChanged method for your search text field
onChanged: (value) {
  if (shouldShowSearchResults) {  // TODO
    _navigatorKey.currentState.pushNamed('contacts/search');
  } else if (shouldHideSearchResults {  // TODO
    _navigatorKey.currentState.pop();
  }
}

...

// New body for your Scaffold
body: new Navigator(
  key: _navigatorKey,
  initialRoute: 'contacts',
  onGenerateRoute: (RouteSettings settings) {
    if (settings.name == 'contacts') {
      return new MaterialPageRoute(
        builder: (_) => new ContactList(kContacts),
        settings: settings
      );
    } else if (settings.name == 'contacts/search') {
      return new MaterialPageRoute(
        builder: (_) => new SearchPage(contacts: kContacts, search: searchValue),  // TODO
        settings: settings
      );
    }
  }
)

...
© www.soinside.com 2019 - 2024. All rights reserved.