简体   繁体   中英

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

I'm new to flutter and programming in general. I'm creating an expansion tile, with more data about the company when expanded like label value fields.

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,
    )
  ],
);
}
}

I'm trying to create a companyValues widget just like companyLabels widget, i have company object in Object.dart file.

When i try to pass company.parameters into the companyValues widget, im getting the error the getter 'values' is'nt defined for the type company

Also please let me know whats the best practice to follow when achieve something like this.

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});
}```

Your variable is called values . Remove the company. prefix.

Problem is in this line

companyValues(company.phoneNumber),

You're passing the string but in function your parameter is Company object

Widget companyValues(Company values) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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