artoniaz
artoniaz

Reputation: 183

Flutter - undefined name of class parameter

I'm having difficulties in this part of my code. It looks preety simple, however there is one thing I just don't understand. This is my class, it looks rather basic:

class _ChangePageItem extends StatelessWidget {
  final String label;
  final bool isActive;
  final int pageIndex;
  final Function handlePagination;

  _ChangePageItem(this.label, this.isActive, this.pageIndex, this.handlePagination);
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 35.0,
      height: 35.0,
      margin: EdgeInsets.only(right: 10.0),
      decoration: BoxDecoration(
        border: Border.all(
          width: 1.0,
          color: Colors.grey,
          style: BorderStyle.solid,
        ),
      ),
      child: RaisedButton(
        color: Colors.white,
        child: Text('$label'),
        onPressed:
            isActive ? () => handlePagination(int.parse('${label}')) : null,
      ),
    );
  }
}

then I'm using this class in the same file:

return Row(
  mainAxisAlignment: MainAxisAlignment.end,
  children: [
    _ChangePageItem(label, isActive, pageIndex, handlePagination),
    paginationsItems(), _PaginationItem(label: '>')],
);

This is the error that I'm getting: enter image description here

Adding value doesn't help: enter image description here

Upvotes: 0

Views: 899

Answers (1)

Er1
Er1

Reputation: 2758

You should call the constructor like this, or using your own variables:

return Row(
  mainAxisAlignment: MainAxisAlignment.end,
  children: [
    _ChangePageItem('A String', true, 0, (){}),
    paginationsItems(), _PaginationItem(label: '>')],
);

Upvotes: 1

Related Questions