0

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

1
  • you can't use named parameters like in the second image. But where you create the variable 'label' in the first image? Commented Nov 16, 2020 at 14:27

1 Answer 1

1

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: '>')],
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.