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
430 views
in Technique[技术] by (71.8m points)

controller - TabBarView not showing screens Flutter

i am trying to implement TabBarView in my app .

i have filter in my app and have placed tababr below that filter and want to place TabBarView below that tabbar but it seems something is wrong .

it is showing black screen if i don't wrap tabbar with scaffold and if i wrap with Scaffold it does not show tab screen here , below is the code

 @override
  void initState() {
    super.initState();
    initializeRawData();
    tabController = TabController(length: 2, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: [
          GestureDetector(
            onTap: () => showChooser(),
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 10.0),
              child: SvgPicture.asset(
                "images/pdf.svg",
                height: 24.0,
                width: 24.0,
                color: MyApplication().hexToColor(AppColors.white),
              ),
            ),
          ),
        ],
        title: Text(
          AppString.balancesheet_screen,
          style: TextStyle(
            fontWeight: FontWeight.bold,
          ),
        ),
        elevation: 4.0,
        flexibleSpace: Container(
          decoration: BoxDecoration(
            color: MyApplication().hexToColor(AppColors.toolbar),
          ),
        ),
      ),
      body: Container(
        decoration: BoxDecoration(
          color: MyApplication().hexToColor(AppColors.off_white),
        ),
        child: Column(
          children: [
            // filter heading
            Container(
              decoration: BoxDecoration(
                color: MyApplication().hexToColor(AppColors.toolbar),
              ),
              padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 16.0),
              // to date filter part
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  // to date column
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "From Date",
                        style: TextStyle(
                          color: MyApplication().hexToColor(AppColors.white),
                          fontWeight: FontWeight.w100,
                          fontSize: 16.0,
                        ),
                      ),
                      SizedBox(height: 10.0),
                      GestureDetector(
                        onTap: () async {
                          String date = await showPickerDialogAndGetDate(
                              context,
                              AppString.PREF_BALANCE_SHEET_FROM_DATE);
                          setState(() {
                            widget.fromDate = date;
                          });
                        },
                        child: Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: 8.0, vertical: 4.0),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(4.0),
                              color: MyApplication()
                                  .hexToColor(AppColors.toobar_dark)),
                          // calendar , date
                          child: Row(
                            children: [
                              SvgPicture.asset(
                                "images/calendar.svg",
                                color: MyApplication()
                                    .hexToColor(AppColors.white),
                                height: 24.0,
                                width: 24.0,
                              ),
                              SizedBox(width: 4.0),
                              Text(
                                widget.fromDate,
                                style: TextStyle(
                                  color: MyApplication()
                                      .hexToColor(AppColors.white),
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                  // to date column
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "To Date",
                        style: TextStyle(
                          color: MyApplication().hexToColor(AppColors.white),
                          fontWeight: FontWeight.w100,
                          fontSize: 16.0,
                        ),
                      ),
                      SizedBox(height: 10.0),
                      GestureDetector(
                        onTap: () async {
                          String date = await showPickerDialogAndGetDate(
                              context, AppString.PREF_BALANCE_SHEET_TO_DATE);
                          setState(() {
                            widget.toDate = date;
                          });
                        },
                        child: Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: 8.0, vertical: 4.0),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(4.0),
                              color: MyApplication()
                                  .hexToColor(AppColors.toobar_dark)),
                          // calendar , date
                          child: Row(
                            children: [
                              SvgPicture.asset(
                                "images/calendar.svg",
                                color:
                                    MyApplication().hexToColor(AppColors.white),
                                height: 24.0,
                                width: 24.0,
                              ),
                              SizedBox(width: 4.0),
                              Text(
                                widget.toDate,
                                style: TextStyle(
                                  color: MyApplication()
                                      .hexToColor(AppColors.white),
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ), //
                ],
              ),
            ),
            balanceSheetTabBar(),
          ],
        ),
      ),
    );
  }

  void showChooser() {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return PDFOptionBottomSheet(
            onChoose: (String action) {
              Toast.show(action, context);
            },
          );
        });
  }

  Widget balanceSheetTabBar() {
    return Container(
      width: double.infinity,
      height: 52.0,
      child: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            backgroundColor: MyApplication().hexToColor(AppColors.white),
            bottom: TabBar(
              controller: tabController,
              labelColor: MyApplication().hexToColor(AppColors.black),
              indicator: UnderlineTabIndicator(
                borderSide: BorderSide(
                    width: 3.0,
                    color: MyApplication().hexToColor(AppColors.toolbar)),
              ),
              labelStyle: TextStyle(
                fontWeight: FontWeight.bold,
                color: MyApplication().hexToColor(AppColors.black),
                fontSize: 18.0,
                fontFamily: AppFontFamily.NormalTextFamily,
              ),
              tabs: [
                Tab(text: AppString.liablitites),
                Tab(text: AppString.assests),
              ],
            ),
          ),
          body: TabBarView(
            controller: tabController,
            children: [
              Icon(Icons.ac_unit),
              Icon(Icons.home)
            ],
          ),
        ),
      ),
    );
  }

Thank You .

question from:https://stackoverflow.com/questions/65517074/tabbarview-not-showing-screens-flutter

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

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

...