有谁知道如何使用flutter来实现带有类似于instagram这样的标签的搜索栏?

时间:2019-04-17 20:41:55

标签: flutter flutter-layout flutter-dependencies flutter-animation flutter-appbar

我想知道如何构建一个搜索栏,在其中将用户搜索输入过滤到组或选项卡中,例如instagram,就像人物,标签,地点一样,但我不知道该怎么做!

1 个答案:

答案 0 :(得分:0)

它看起来像这样:

import 'package:flutter/material.dart';

main() => runApp(
      MaterialApp(
//          home: Scaffold(
//        body: Container(child: SearchButton()),
          home: Body()),
    );

class Body extends StatefulWidget {
  @override
  _BodyState createState() => _BodyState();
}

class _BodyState extends State<Body> {
  TextEditingController controller;

  @override
  void initState() {
    super.initState();
    controller = TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          leading: Icon(Icons.search),
          title: TextField(
            controller: controller,
            cursorColor: Colors.white,
            style: TextStyle(color: Colors.white),
          ),
          bottom: TabBar(tabs: [
            Tab(icon: Icon(Icons.people)),
            Tab(icon: Icon(Icons.location_city)),
          ]),
        ),
        body: TabBarView(children: [Container(), Container()]),
      ),
    );
  }
}

想要的结果:enter image description here

代码结果:enter image description here