在DefaultTabController中填充AppBar

时间:2017-05-30 18:21:20

标签: dart flutter

我正在使用带有Scaffold的DefaultTabController作为子窗口小部件。对于appBar,我正在使用TabBar。我想在TabBar周围添加一些填充,但appBar属性需要一个扩展PreferredSizeWidget的类。

我正在构建的标签控制器的示例代码段:

  new DefaultTabController(
    length: tabs.length,
    child: new Scaffold(
      backgroundColor: const Color(0xFFF3EEE1),
      appBar: new TabBar(
        tabs: tabs,
      ),
      body: new TabBarView(
        children: _testPacks.map((TestPack testPack) {
          return _contentWidget(context: context, testPack: testPack);
        }).toList(),
      ),
    ),
  );

来自脚手架课程

/// An app bar to display at the top of the scaffold.
final PreferredSizeWidget appBar;

2 个答案:

答案 0 :(得分:1)

您可以将TabBar的{​​{1}}包裹在PreferredSize中。

答案 1 :(得分:1)

现在您可以通过自定义填充

public void createServiceAccountKey(String serviceAccountName) 
      {
        ServiceAccountKey serviceAccountKey = null;
        try {
          initService();

          serviceAccountKey =
              service
                  .projects()
                  .serviceAccounts()
                  .keys()
                  .create(
                      "projects/-/serviceAccounts/"
                          + serviceAccountName
                          + "@"
                          + serviceAccountConfig.getProjectId()
                          + ".iam.gserviceaccount.com",
                      new CreateServiceAccountKeyRequest())
                  .execute();

          log.info("Created key under Service Account: {}", serviceAccountName);
          log.info("Service Account Private Data: ", serviceAccountKey.getPrivateKeyData());
          log.info("Service Account Key Type: ", serviceAccountKey.getKeyType());
          log.info("Service Account Key Type: ", serviceAccountKey.getKeyAlgorithm());

        } catch (IOException e) {
          log.error("Unable to create key under service account: {}", e.toString());
        }
      }