Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
877 views
in Technique[技术] by (71.8m points)

Flutter - TabBar inside Column

I have a Column with an Image and below it a DefaultTabController. The TabBar basically does not display the tabs, but the children of the TabBarView are displayed.

That's the error:

Null check operator used on a null value The relevant error-causing widget was TabBar lib/…/screens/specific_launch.dart:132 The following RenderObject was being processed when the exception was fired: RenderCustomPaint#83c8d relayoutBoundary=up10 RenderObject: RenderCustomPaint#83c8d relayoutBoundary=up10 parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size) constraints: BoxConstraints(0.0<=w<=336.0, 0.0<=h<=Infinity) size: Size(336.0, 100000.0) child: RenderErrorBox#daadf NEEDS-PAINT parentData: (can use size) constraints: BoxConstraints(0.0<=w<=336.0, 0.0<=h<=Infinity) size: Size(336.0, 100000.0)

That's the code:

 return Scaffold(
    appBar: AppBar(
      title: Text(
        'Launch',
        style: GoogleFonts.poppins(fontWeight: FontWeight.w600),
      ),
      actions: [
        IconButton(icon: Icon(Icons.share_outlined), onPressed: () {})
      ],
    ),
    body: Padding(
      padding: EdgeInsets.only(
          top: getHeight(context) / 30.0,
          left: getWidth(context) / 30.0,
          right: getWidth(context) / 30.0),
      child: Column(
        children: [
          // ...first child


          SizedBox(
            width: getWidth(context),
            height: getHeight(context),
            child: DefaultTabController(
                length: 3,
                initialIndex: 0,
                child: Scaffold(
                  appBar: AppBar(
                    bottom: TabBar(
                      tabs: [
                        Tab(
                          text: 'State',
                        ),
                        Tab(
                          text: 'Mission',
                        ),
                        Tab(
                          text: 'Rocket',
                        )
                      ],
                    ),
                  ),
                  body: TabBarView(
                    children: [
                      Text(
                        'Tab 1',
                      ),
                      Text('Tab 2'),
                      Text('Tab 3')
                    ],
                  ),
                )),
          )
        ],
      ),
    ));

That's the result I'm trying to achieve:

Results

question from:https://stackoverflow.com/questions/65858554/flutter-tabbar-inside-column

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So if you want to use the DefaultTabController widget then you must start your widget tree with the DefaultTabController widget and then add your Scaffold. After that I used only one Scaffold and added rest of part with the help of Expanded widget

Here is output image

class SelectionScreen extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _selectionScreen();
  }
}
class _selectionScreen extends State<SelectionScreen>{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return DefaultTabController(
        length: 3,
        initialIndex: 0,
        child: Scaffold(
          appBar: AppBar(
            title: Text('Launch',),
            actions: [IconButton(icon: Icon(Icons.share_outlined), onPressed: () {})],
          ),
          body: Column(
            children: [
              Image.network("https://i.stack.imgur.com/45Aaj.png", height: 150,),
              Container(
                height: 70,
                child: AppBar(
                  centerTitle: true,
                  title: Text("New Titile"),
                  bottom: TabBar(
                    tabs: [
                      Tab(text: 'State',),
                      Tab(text: 'Mission',),
                      Tab(text: 'Rocket',)
                    ],
                  ),
                ),
              ),
              Expanded(
                child: TabBarView(
                  children: [
                    Text('Tab 1',),
                    Text('Tab 2'),
                    Text('Tab 3')
                  ],
                ),
              )
            ],
          ),
        ));
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...