选项卡未显示在颤动中 [英] Tabs are not displaying in the flutter

查看:62
本文介绍了选项卡未显示在颤动中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在Flutter中构建一个应用程序.我想在屏幕上显示标签.我正在尝试以下操作,但未显示标签.

Hi I am trying to build an app in the flutter. I want to have tabs in my screen. I am trying like below but it is not displaying tabs.

有人知道这是什么原因吗?

Does anyone know what is the reason of it ?

class DashboardScreen extends StatelessWidget {
  Widget bodyData() => SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: DefaultTabController(
                  length: 3,
                  child: Scaffold(
                    appBar: AppBar(
                      bottom: TabBar(
                        tabs: [
                          Tab(icon: Icon(Icons.directions_car)),
                          Tab(icon: Icon(Icons.directions_transit)),
                          Tab(icon: Icon(Icons.directions_bike)),
                        ],
                      ),
                      title: Text('Tabs Demo'),
                    ),
                    body: TabBarView(
                      children: [
                        Icon(Icons.directions_car),
                        Icon(Icons.directions_transit),
                        Icon(Icons.directions_bike),
                      ],
                    ),
                  ),
                ),
              ),
              SizedBox(
                height: 10.0,
              ),
            ],
          ),
        ),
      );

  @override
  Widget build(BuildContext context) {
    return CommonScaffold(
      appTitle: "Pay",
      showDrawer: true,
      bodyData: bodyData(),
    );
  }
}

当我有以下代码时,它将正确显示文本.

When I have below code then it display the text correctly.

  Widget bodyData() => SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Center(
                  child: Text(
                    "Pay Your Bills",
                    style:
                        TextStyle(fontWeight: FontWeight.w700, fontSize: 20.0),
                  ),
                ),
              ),
              SizedBox(
                height: 10.0,
              ),
            ],
          ),
        ),
      );

推荐答案

我不知道您确切想要创建什么,但是它们是您的代码中的几个问题. 您可以检查以下代码,使其在标签"视图中正常运行.

i don't know what you exactly want to create but their are several problems with your code. you can check below code it works fine for Tab view.

import 'package:flutter/material.dart';

  void main() {
    runApp(MyHomePage());
  }

  class MyHomePage extends StatelessWidget {

    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        theme: new ThemeData(
          accentColor: Colors.blue,
        ),
        home: DashboardScreen(),
      );
    }
  }
  class DashboardScreen extends StatelessWidget {
    Widget bodyData() =>
        DefaultTabController(
          length: 3,
          child: Scaffold(
            appBar: AppBar(
              bottom: TabBar(
                tabs: [
                  Tab(icon: Icon(Icons.directions_car)),
                  Tab(icon: Icon(Icons.directions_transit)),
                  Tab(icon: Icon(Icons.directions_bike)),
                ],
              ),
              title: Text('Tabs Demo'),
            ),
            body: TabBarView(
              children: [
                Icon(Icons.directions_car),
                Icon(Icons.directions_transit),
                Icon(Icons.directions_bike),
              ],
            ),
          ),
        );


    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: bodyData(),
      );
    }
  }

这篇关于选项卡未显示在颤动中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆