Flutter:动态连接TabBar选项卡和TabBarView

时间:2020-04-28 10:41:48

标签: flutter tabbar

如您所见,我有一个由标签'suj.subSec'制成的TabBar,

. . .
set value = (case when <complicated expression here> then 1 else 0 end)

然后在TabBarView中显示与CartaoPonto制作的选项卡相对应的列表:

appBar: AppBar(
        title: Text(suj.titulo),
        centerTitle: true,
        bottom: TabBar(
          controller: _tabController,
          tabs: suj.subSec,
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: List<Widget>.generate(suj.subSec.length, (int index){

          var listaDest = suj.dest[index];

          return SingleChildScrollView(
            padding: EdgeInsets.all(10),
            child: Column(
              children: <Widget>[
                Container(
                  child: ListView.builder(
                    shrinkWrap: true,
                    physics: ClampingScrollPhysics(),
                    itemCount: listaDest.length,
                    itemBuilder: (BuildContext context, int indx) {
                      return CartaoPonto(listaDest, indx);
                    },
                  ),
                ),```

但是,要进行此锻炼,我必须有2个相应的列表,firts是一个Tabs List,第二个是List od Lists,因此我可以对我的构建器说,得到带有与标签索引。

class CartaoPonto extends StatelessWidget {

  var listaDest;
  int index;

  CartaoPonto(this.listaDest, this.index);

  @override
  Widget build(BuildContext context) {
    return Container(
        margin: EdgeInsets.only(bottom: 8),
        decoration: BoxDecoration(
            color: Color(0xffE9F4F9), borderRadius: BorderRadius.circular(20)),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            ClipRRect(
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(20),
                  bottomLeft: Radius.circular(20)),
              child: Placeholder(
                fallbackHeight: 90,
                fallbackWidth: 110,
              ),
            ),
            Flexible(
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 16),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      listaDest[index].titulo.toString(),

我该如何以更直接,更动态的方式做到这一点?

0 个答案:

没有答案