如何在流中使用标签栏和标签栏视图

时间:2018-10-28 18:42:13

标签: stream flutter tabbar

我正在尝试添加标签栏和标签栏视图。但是,应该从流中监听标签和标签栏视图的值, 首先,这存在一些问题:随着流的长度变化,我不知道如何确定选项卡栏默认控制器的长度。另外,我尝试在选项卡barview中使用琐碎的图标(而不是我想听的流)来了解它是否将起作用。我试图那样做:

class HomePage extends StatelessWidget {

  final FirebaseUser user;


  HomePage({this.user});

  @override
  Widget build(BuildContext context) {
    return new DefaultTabController(
      length: 20, `//I wrote 20 to only run `the code however, it should be the length of the stream but i don't know how to get it???
      child: Scaffold(
      appBar: AppBar(
        title: Text("Home Page"),
      ),
  body:Column(
  children:<Widget>[ StreamBuilder<QuerySnapshot>(
    stream: Firestore.instance.collection("places").snapshots(),
    builder: (BuildContext context,AsyncSnapshot<QuerySnapshot> snapshot){


      if (!snapshot.hasData){
        return Center(child: CircularProgressIndicator());
      }
      else{
        return Column(
           children:<Widget>
         [
           TabBar( isScrollable: true,
              tabs: new List.generate(snapshot.data.documents.length, (index) {
                    return new Tab(child: Text(snapshot.data.documents[index]['name'].toString().toUpperCase()));

                      //String f=snapshot.data.documents[index]["Place"].toString();




                               // print( Firestore.instance.collection("Places").document(f).collection("order 1").document('order 1').snapshots().toString());

                            }       
          ) 
          ),

          TabBarView(
          children: <Widget>[
            Icon(Icons.directions_car),
            Icon(Icons.directions_transit),
            Icon(Icons.directions_bike),
          ],
        )
        ],
        );}


    })
  ]) 
  )
     ); }
    }

标签栏起作用。但是,图标(位于选项卡视图中的图标在我在选项卡之间导航时不会出现)。有什么帮助吗? 预先感谢。

0 个答案:

没有答案