dart 在抖动中如何在文本超过特定空格时换行

jhdbpxl9  于 2023-03-21  发布在  其他
关注(0)|答案(1)|浏览(122)

我怎样才能把'备注'文本换行,因为它是一个错误的文本溢出。在“备注”,如果它的文本长度较长,那么它应该自动从新行开始:

Flexible(child: SizedBox(
                                child: Padding(
                                  padding: const EdgeInsets.only(
                                    left: 6,
                                    right: 10,
                                    top: 3,
                                  ),
                                  child: ListView.builder(
                                      padding: EdgeInsets.zero,

                                          // scrollDirection: Axis.vertical,
                                          shrinkWrap: true,
                                          itemCount: transLenght.length,
                                          itemBuilder: (context, index) {
                                            // print(
                                            //     'invtr lengh ${transLenght.length}');
                                            // List trns = transLenght[index];
    
                                            final trType = transLenght[index]
                                                ['transaction_type'];
    
                                            final trAmount = transLenght[index]
                                                    ['amount']
                                                .toString();
                                            String trmt =
                                                double.parse(trAmount as String)
                                                    .toStringAsFixed(2)
                                                    .toString()
                                                    .replaceAllMapped(
                                                        reg, mathFunc);
                                            this.trmt = trmt;
                                            print(
                                                'trAmount type ${trAmount.runtimeType}');
    
                                            // String trmt =
                                            //     double.parse(trAmount as String)
                                            //         .toStringAsFixed(2)
                                            //         .toString()
                                            //         .replaceAllMapped(
                                            //             reg, mathFunc);
                                            //   final trmt =
                                            //       double.parse(trAmount.toString())
                                            //           .toStringAsFixed(2);
                                            //   this.trmt = trmt;
                                            // } else {
                                            //   String tramnt = trAmount.toString();
                                            //   String trmt = tramnt.replaceAllMapped(
                                            //       reg, mathFunc);
                                            //   this.trmt = trmt;
                                            // }
                                            // } else {
                                            //   String trmt = trAmount
                                            //       .replaceAllMapped(reg, mathFunc);
                                            //   this.trmt = trmt;
                                            // }
    
                                            // String tramt =
                                            //     double.parse(trmt.toString())
                                            //         .toStringAsFixed(2);
    
                                            final trDate = transLenght[index]
                                                ['transaction_date'];
                                            DateTime trdt = DateTime.parse(
                                                trDate); //invoice date
    
                                            String transdt =
                                                DateFormat("dd-MMM-yyyy")
                                                    .format(trdt);
                                            final trRemark =
                                                transLenght[index]['remark'];
                                            final trinterest = transLenght[index]
                                                    ['interest'] ??
                                                '';
                                            if (trinterest == 0.0) {
                                              String intrst = trinterest.toString();
                                              intrst = '';
                                            } else {
                                              String intrst = trinterest.toString();
                                              this.intrst = intrst;
                                            }
                                            final trdisc = transLenght[index]
                                                    ['discount'] ??
                                                '';
    
                                            if (trdisc is double) {
                                              // final trDiscount = trdisc.toString();
                                              final discnt =
                                                  double.parse(trdisc.toString())
                                                      .toStringAsFixed(2);
                                              this.discnt = discnt;
                                            } else {
                                              if (trdisc == 0.0) {
                                                String discnt = trdisc.toString();
                                                this.discnt = '';
                                              } else {
                                                String discnt1 = trdisc.toString();
                                                String discnt =
                                                    discnt1.replaceAllMapped(
                                                        reg, mathFunc);
                                                this.discnt = discnt;
                                              }
                                            }
                                            // else {
                                            //   String discnt1 = trdisc.toString();
                                            //   String discnt = discnt1
                                            //       .replaceAllMapped(reg, mathFunc);
                                            //   this.discnt = discnt;
                                            // }
    
                                            final amtCleared = transLenght[index]
                                                    ['transaction_amount'] ??
                                                '';
                                            String clrAmt =
                                                double.parse(amtCleared as String)
                                                    .toStringAsFixed(2)
                                                    .toString()
                                                    .replaceAllMapped(
                                                        reg, mathFunc);
                                            this.clrAmt = clrAmt;
                                            print(
                                                'trAmount type ${trAmount.runtimeType}');
    
                                            // if (amtCleared is double) {
                                            //   final clrAmt = double.parse(
                                            //           amtCleared.toString())
                                            //       .toStringAsFixed(2);
                                            //   this.clrAmt = clrAmt;
                                            // } else {
                                            //   String clramt1 =
                                            //       amtCleared.toString();
                                            //   String clrAmt = clramt1
                                            //       .replaceAllMapped(reg, mathFunc);
                                            //   this.clrAmt = clrAmt;
                                            // }
    
                                            return Card(
                                                shadowColor: Color.fromARGB(
                                                    255, 245, 175, 45),
                                                elevation: 5,
                                                child: Padding(
                                                  padding: const EdgeInsets.only(
                                                    left: 12,
                                                    right: 14,
                                                    top: 12,
                                                  ),
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment.start,
                                                    children: [
                                                      Column(
                                                        crossAxisAlignment:
                                                            CrossAxisAlignment
                                                                .start,
                                                        children: [
                                                          Text(
                                                            "Transaction Type",
                                                            style: TextStyle(
                                                              fontSize: 13,
                                                            ),
                                                          ),
                                                          Text(
                                                            "$trType",
                                                            style: TextStyle(
                                                                fontSize: 15,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .bold),
                                                          ),
                                                          SizedBox(height: 15),
                                                          Text(
                                                            "Transaction Amount",
                                                            style: TextStyle(
                                                              fontSize: 13,
                                                            ),
                                                          ),
                                                          Text(
                                                            "$trmt",
                                                            style: TextStyle(
                                                                fontSize: 15,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .bold),
                                                          ),
                                                          SizedBox(height: 15),
                                                          Text(
                                                            "Transaction Date",
                                                            style: TextStyle(
                                                              fontSize: 13,
                                                            ),
                                                          ),
                                                          Text(
                                                            "$transdt",
                                                            style: TextStyle(
                                                                fontSize: 15,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .bold),
                                                          ),
                                                          SizedBox(height: 15),
                                                          Text(
                                                            "Amount Cleared",
                                                            style: TextStyle(
                                                              fontSize: 13,
                                                            ),
                                                          ),
                                                          Text(
                                                            "$clrAmt",
                                                            style: TextStyle(
                                                                fontSize: 15,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .bold),
                                                          ),
                                                          SizedBox(height: 6),
                                                        ],
                                                      ),
                                                      SizedBox(
                                                        width: w10p * 2.9,
                                                      ),
                                                      Column(
                                                        mainAxisAlignment:
                                                            MainAxisAlignment.start,
                                                        crossAxisAlignment:
                                                            CrossAxisAlignment
                                                                .start,
                                                        children: [
                                                          Text(
                                                            "Interest",
                                                            style: TextStyle(
                                                              fontSize: 13,
                                                            ),
                                                          ),
                                                          Text(
                                                            "$intrst",
                                                            style: TextStyle(
                                                                fontSize: 13,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .bold),
                                                          ),
                                                          SizedBox(height: 15),
                                                          Text(
                                                            "Discount",
                                                            style: TextStyle(
                                                              fontSize: 13,
                                                            ),
                                                          ),
                                                          Text(
                                                            "$discnt",
                                                            style: TextStyle(
                                                                fontSize: 13,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .bold),
                                                          ),
                                                          SizedBox(height: 15),
                                                          Text(
                                                            "Remarks",
                                                            style: TextStyle(
                                                              fontSize: 13,
                                                            ),
                                                          ),
    
                                                          Text(
                                                            "$trRemark",
                                                            style: TextStyle(
                                                                fontSize: 13,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .bold),
                                                          ),
                                                          // SizedBox(height: 40),
                                                          Text(
                                                            "",
                                                            style: TextStyle(
                                                              fontSize: 12,
                                                            ),
                                                          ),
                                                          Text(
                                                            "",
                                                            style: TextStyle(
                                                                fontSize: 14,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .bold),
                                                          ),
                                                          Text(
                                                            "",
                                                            style: TextStyle(
                                                              fontSize: 12,
                                                            ),
                                                          ),
                                                          Text(
                                                            "",
                                                            style: TextStyle(
                                                              fontSize: 12,
                                                            ),
                                                          ),
                                                        ],
                                                      )
                                                    ],
                                                  ),
                                                ));
                                          }),
                                    ),
                                  ),
                                ),
62o28rlo

62o28rlo1#

您可以使用FlexibleExpanded小工具,也可以使用Text小工具的maxLines属性。
请尝试以下代码:

Flexible(
              child: Text(
                "$trRemark",
                maxLines: 2,
                style: TextStyle(fontSize: 13, fontWeight: FontWeight.bold),
              ),
            ),

相关问题