簡體   English   中英

我正在嘗試將 object.parameter 傳遞給自定義小部件並失敗

[英]I'm trying to pass object.parameter into a custom widget and failing

我是 flutter 和一般編程的新手。 我正在創建一個擴展磁貼,在擴展時包含更多關於公司的數據,例如 label 值字段。

import 'package:flutter/material.dart';
import '../Object.dart';

class CompanyCardStyle extends StatelessWidget {
  final Company company;
CompanyCardStyle({this.company});

@override
Widget build(BuildContext context) {
return Card(
    margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0),
    child: ExpansionTile(
      
      title: Text(company.name),
      children: <Widget>[
        Container(
            padding: const EdgeInsets.all(15.0),
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Column(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      companyLabels('Phone Number'),
                      companyLabels('Opportunities'),
                      companyLabels('Pipeline Revenue'),
                      companyLabels('Revenue Achieved'),
                    ],
                  ),
                  Container(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        companyValues(company.phoneNumber),
                        SizedBox(
                          height: 10,
                        ),
                        Text(
                          company.opportunities.toString(),
                          textAlign: TextAlign.left,
                          style: TextStyle(
                              fontFamily: 'Raleway', fontSize: 15.0),
                        ),
                        SizedBox(
                          height: 10,
                        ),
                        Text(
                          company.pRevenue.toString(),
                          textAlign: TextAlign.left,
                          style: TextStyle(
                              fontFamily: 'Raleway', fontSize: 15.0),
                        ),
                        SizedBox(
                          height: 10,
                        ),
                        Text(
                          company.revenueAchieved.toString(),
                          textAlign: TextAlign.left,
                          style: TextStyle(
                              fontFamily: 'Raleway', fontSize: 15.0),
                        )
                      ],
                    ),
                  )
                ]))
      ],
      leading: CircleAvatar(child: Text(company.name[0])),
      subtitle: Text(company.address),
    ));
}

Widget companyLabels(String values) {
return Row(children: <Widget>[
  Text(
    values.toString(),
    textAlign: TextAlign.left,
    style: TextStyle(
        fontFamily: 'Raleway', fontSize: 15.0, fontWeight: FontWeight.bold),
  ),
  SizedBox(
    height: 30,
  )
]);
}

Widget companyValues(Company values) {
return Row(
  children: <Widget>[
    Text(
      company.values.toString(),
      textAlign: TextAlign.left,
      style: TextStyle(fontFamily: 'Raleway', fontSize: 15.0),
    ),
    SizedBox(
      height: 10,
    )
  ],
);
}
}

我正在嘗試創建一個 companyValues 小部件,就像 companyLabels 小部件一樣,我在 Object.dart 文件中有公司 object。

當我嘗試將 company.parameters 傳遞到 companyValues 小部件時,我收到錯誤the getter 'values' is'nt defined for the type company

另外,請讓我知道實現此類目標時要遵循的最佳實踐是什么。

公司 Object

  String name;
  String address;
  int phoneNumber;
  int opportunities;
  int pRevenue;
  int revenueAchieved;

  Company(
      {this.name,
      this.address,
      this.opportunities,
      this.pRevenue,
      this.phoneNumber,
      this.revenueAchieved});
}```

您的變量稱為values 刪除company. 字首。

問題出在這一行

companyValues(company.phoneNumber),

您正在傳遞字符串,但在 function 中,您的參數是Company object

Widget companyValues(Company values) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM