简体   繁体   English

如何在 flutter 中制作嵌套表格

[英]How to make a nested Table in flutter

So, I wanted to make a nested Table Row in Flutter basically something like this所以,我想在 Flutter 中制作一个嵌套的表格行,基本上是这样

class _MyHomeState extends State<MyHome> {
 var dat=" ";
 myTableRow(day,period1,period2,period3,period4,period5,period6,period7,period8)
 {
   return TableRow(
       children: [
         Text(day),
         Text(period1),
         Text(period2),
         Text(period3),
         Text(period4),
         Text(period5),
         Text(period6),
         Text(period7),
         Text(period8),
       ]
   );
 }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        centerTitle: true,
            title: Text('Time Table App'),
      ),
      body: Container(
        margin: EdgeInsets.only(left: 30,right: 30),
          child:RotatedBox(
            quarterTurns: 3,
            child:Table(
        border: TableBorder.all(),
        children:[
           TableRow(
              children:[
                Text("COA"),
                TableRow(
                   children: [
                     Text("COA"),
                     Text("DSTL")
                             ]),
                  ])
            ])
    )));
  }
}

I have made a function for seperate Table Rows so, that I can give Text Styles to any or all of them depending upon user input... and rotated the table so that it does not appear cluncky to the user...now nesting the tables is not working to make a table like that so do I use columns and rows or table rows can be nested but I'm not doing it the right way?我为单独的表行制作了一个 function,这样我就可以根据用户输入将文本 Styles 提供给其中的任何一个或所有...并旋转表,这样它就不会对用户显得笨拙...现在嵌套表格无法制作这样的表格,所以我是使用列和行,还是可以嵌套表格行,但我的做法不正确?

Since TableRow accepts any widget in children, you can easily nest a table inside a table.由于TableRow接受子项中的任何小部件,因此您可以轻松地将表格嵌套在表格中。 Please check the following code, you can run it in Dartpad.请检查以下代码,您可以在 Dartpad 中运行它。

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Table(border: TableBorder.all(), children: [
            const TableRow(children: [
              Text('Column 1'),
              Text('Column 2'),
            ]),
            TableRow(children: [
              const Text('Entry 1'),
              Table(border: TableBorder.all(), children: const [
                TableRow(children: [
                  Text('Nested Entry 1'),
                  Text('Nested Entry 2'),
                ]),
                TableRow(children: [
                  Text('Nested Entry 3'),
                  Text('Nested Entry 4'),
                ]),
              ]),
            ]),
          ]),
        ),
      ),
    );
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM