flutter单击按钮时显示文本字段图标按钮

tp5buhyn  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(171)

"我的问题"
单击按钮时,按钮底部将显示“我想制作搜索图标”按钮文本字段
是否有我可以参考的文档或网站?

我的代码--使状态小部件--

appBar: AppBar(
          backgroundColor: const Color(0xffffffff),
          centerTitle: true,
          title: Text(
            'CREW',
            style: TextStyle(color: Colors.black, fontWeight: FontWeight.w900),
          ),
          elevation: 0.0,
          actions: [
            IconButton(icon: Icon(Icons.search), onPressed: (){
            }),
            IconButton(icon: Icon(Icons.notifications), onPressed: null),
          ],
brvekthn

brvekthn1#

**Try below code to add search bar in appbar.**

 

    AppBar(
               backgroundColor: const Color(0xffffffff),
          centerTitle: true,
          title: Text(
            'CREW',
            style: TextStyle(color: Colors.black, fontWeight: FontWeight.w900),
          ),
          elevation: 0.0,
                actions: [
                  // Navigate to the Search Screen
                  IconButton(
                      onPressed: () => Navigator.of(context)
                          .push(MaterialPageRoute(builder: (_) => const SearchPage())),
                      icon: const Icon(Icons.search)),
                IconButton(icon: Icon(Icons.notifications), onPressed: null),
        
                ],
              ),

//搜索UI页面(& P)

class SearchPage extends StatelessWidget {
  const SearchPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          // The search area here
          title: Container(
        width: double.infinity,
        height: 40,
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.circular(5)),
        child: Center(
          child: TextField(
            decoration: InputDecoration(
                prefixIcon: const Icon(Icons.search),
                suffixIcon: IconButton(
                  icon: const Icon(Icons.clear),
                  onPressed: () {
                    /* Clear the search field */
                  },
                ),
                hintText: 'Search...',
                border: InputBorder.none),
          ),
        ),
      )),
    );
  }

相关问题