如何在TabBarView中插入Column?

问题描述 投票:0回答:1

我在这里有一个疑问...我想知道如何将 2 个 TextField 放入同一个 TabBar 中,因为第二个 TextField 显示在另一个选项卡中。

抱歉,如果解释得不好。

body: TabBarView(
  children: [
    new Padding(
      padding: EdgeInsets.fromLTRB(100.0, 50, 100.0, 1),
      child: TextField(
        controller: nota1Controller,
        keyboardType: TextInputType.number,
        decoration: InputDecoration(
          hintText: "Nota 1",
          hintStyle: TextStyle(color: Colors.green),
          filled: true,
          fillColor: Colors.green.shade50,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(10),
            borderSide: BorderSide.none,
          ),
        ),
        textAlign: TextAlign.left,
        style: TextStyle(color: Colors.green, fontSize: 20.0),
      ),
    ),

    new Padding(
      padding: EdgeInsets.fromLTRB(100.0, 50, 100.0, 1),
      child: TextField(
        controller: nota2Controller,
        keyboardType: TextInputType.number,
        decoration: InputDecoration(
          hintText: "Nota 2",
          hintStyle: TextStyle(color: Colors.green),
          filled: true,
          fillColor: Colors.green.shade50,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(10),
            borderSide: BorderSide.none,
          ),
        ),
        textAlign: TextAlign.left,
        style: TextStyle(color: Colors.green, fontSize: 20.0),
      ),
    ),

我期待在列中显示我的所有文本字段。

flutter dart tabbar
1个回答
0
投票

这是因为您要向

new Padding
添加两个子项 (
TabBarView
)。将两个
Padding
小部件放入
Column
小部件中,两个
TextField
将显示在同一个选项卡中。

body: TabBarView(
  children: [
    new Column(
     children: [
    new Padding(
      padding: EdgeInsets.fromLTRB(100.0, 50, 100.0, 1),
      child: TextField(
        controller: nota1Controller,
        keyboardType: TextInputType.number,
        decoration: InputDecoration(
          hintText: "Nota 1",
          hintStyle: TextStyle(color: Colors.green),
          filled: true,
          fillColor: Colors.green.shade50,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(10),
            borderSide: BorderSide.none,
          ),
        ),
        textAlign: TextAlign.left,
        style: TextStyle(color: Colors.green, fontSize: 20.0),
      ),
    ),

    new Padding(
      padding: EdgeInsets.fromLTRB(100.0, 50, 100.0, 1),
      child: TextField(
        controller: nota2Controller,
        keyboardType: TextInputType.number,
        decoration: InputDecoration(
          hintText: "Nota 2",
          hintStyle: TextStyle(color: Colors.green),
          filled: true,
          fillColor: Colors.green.shade50,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(10),
            borderSide: BorderSide.none,
          ),
        ),
        textAlign: TextAlign.left,
        style: TextStyle(color: Colors.green, fontSize: 20.0),
      ),
    ),
]
)

此外,您不需要在小部件中使用

new
关键字,因为 dart/flutter 不再需要它。

© www.soinside.com 2019 - 2024. All rights reserved.