flutter_chips_input icon indicating copy to clipboard operation
flutter_chips_input copied to clipboard

How to add chip on setState method?

Open appstute-pratik opened this issue 5 years ago • 4 comments

I have added an initial list to InputChip widget, want to add chip on setState method. My list gets updated but chip not displayed on UI. Please help. I'm using 1.6.0 version.

appstute-pratik avatar Feb 27 '20 07:02 appstute-pratik

I faced the same problem. I believe the idiomatic solution would be a controller, similar to the TextEditingController that can be used for TextFields, but that requires the maintainer to change the package.

Luckily the same thing can be achieved using a GlobalKey<ChipsInputState<T>> for a ChipsInput<T>. Roughly like this

class MyWidget extends StatelessWidget {
  final _chipsKey = GlobalKey<ChipsInputState<int>>();

  @override
  Widget build(BuildContext context) {
    return ChipsInput(
       key: _chipsKey,
      );
  }
  void addChip(int chip) {
     _chipsKey.currentState.selectSuggestion(chip);
  }
}

Isodome avatar Apr 11 '20 12:04 Isodome

Thanks @Isodome for your response. That should work.

The plan is to add a ChipsInputController in the next major version

danvick avatar Apr 13 '20 12:04 danvick

I'm having the same issue. While using selectSuggestion works, it still a workaround. Any idea on when you will release your next major release ?

Nico04 avatar Jun 05 '20 17:06 Nico04

I'm having the same issue. While using selectSuggestion works, it still a workaround. Any idea on when you will release your next major release ?

Hi @Nico04, I appreciate your patience. However, my schedule is a bit tight (I'm currently working on this and other opensource projects on weekends) and thus it may not be possible to give a date at this moment.

I'll, however, give this the highest priority as this project has been neglected for a bit :-(

danvick avatar Jun 06 '20 20:06 danvick