为什么从其他文件导入小部件时不显示小部件?

时间:2020-08-19 12:24:23

标签: flutter

FLUTTER:我试图将我的主窗口小部件分隔为不同的窗口,因此应用程序更快,代码也更好。我有主文件(invoice.dart),并在其中从不同的文件导入两个不同的小部件:

两者之间有很大的空间,如何移除?

主文件:

   class Invoice extends StatefulWidget {
  @override
  InvoiceState createState() => InvoiceState();
}

class InvoiceState extends State<Invoice> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
            alignment: Alignment.center,
            child: Column(children: <Widget>[
              Expanded(
                child: TopPart(),
              ),
              Expanded(
                child: RecentTransactions(),
              )
            ])));
  }
}

其他小工具:

class RecentTransactionsState extends State<RecentTransactions> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Expanded(
          child: Container(
            height: 300,
            padding: EdgeInsets.all(21.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Text(
                  'RECENT TRANSACTIONS',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 17.0,
                  ),
                ),
                Expanded(
                  child: ListView(
                    children: <Widget>[
                      Transaction(
                        concept: 'July Rent',
                        transactionAmout: '800.00',
                        transactionDate: '01 Jul 2020',
                        transactionInfo: 'Co-living',
                        transactionType: TransactionType.sent,
                      ),
                      Transaction(
                        concept: '6h Co-working space',
                        transactionAmout: '60.00',
                        transactionDate: '26 Jun 2019',
                        transactionInfo: 'Co-working',
                        transactionType: TransactionType.received,
                      ),
                      Transaction(
                        concept: 'Laundry',
                        transactionAmout: '20.0',
                        transactionDate: '19 Jun 2019',
                        transactionInfo: 'Extra Services',
                        transactionType: TransactionType.pending,
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

其他小工具:

body: Column(
        children: <Widget>[
          SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                  padding: EdgeInsets.all(20),
                  color: Color(0xFF89C9B8),
                  child: Column(
                    children: <Widget>[
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Text(
                                'Hey (name),',
                                style: TextStyle(
                                    fontSize: 25.0,
                                    fontWeight: FontWeight.bold),
                              ),
                              SizedBox(height: 12.0),
                              Text(
                                'Those are all your invoices',
                                style: TextStyle(
                                    fontSize: 20.0, color: Colors.white70),
                              ),
                            ],
                          ),
                          Container(
                              height: 90.0,
                              width: 90.0,
                              decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                image: DecorationImage(
                                    fit: BoxFit.fill,
                                    image: AssetImage('assets/img/woman.png')),
                              )),
                        ],
                      ),
                      // SizedBox(
                      //   height: 15.0,
                      // ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

使用过:

alignment: Alignment.center,
            child: Column(children: <Widget>[
              SizedBox(
                height: 150.0,
                child: Expanded(
                  child: TopPart(),
                ),
              ),
              SizedBox(height: 2.0),
              Expanded(
                child: RecentTransactions(),
              )
            ])));
  }