Dn-a / flutter_tags

With flutter tags you can create selectable or input tags that automatically adapt to the screen width
https://pub.dartlang.org/packages/flutter_tags
MIT License
508 stars 124 forks source link

the method of selectable tags is called every second #10

Closed bzd2000 closed 5 years ago

bzd2000 commented 5 years ago

I have put some log at the start of the build and it seems to be called every second.

I/flutter (27503): build selectableTags [] I/flutter (27503): build selectableTags [] I/chatty (27503): uid=10085(eu.delperdange.pmp_app) Thread-3 identical 158 lines I/flutter (27503): build selectableTags [] I/flutter (27503): build selectableTags [] I/chatty (27503): uid=10085(eu.delperdange.pmp_app) Thread-3 identical 148 lines I/flutter (27503): build selectableTags [] I/flutter (27503): build selectableTags [] I/chatty (27503): uid=10085(eu.delperdange.pmp_app) Thread-3 identical 133 lines I/flutter (27503): build selectableTags [] I/flutter (27503): build selectableTags [] I/chatty (27503): uid=10085(eu.delperdange.pmp_app) Thread-3 identical 163 lines I/flutter (27503): build selectableTags [] I/flutter (27503): build selectableTags []

Dn-a commented 5 years ago

@bzd2000 please post your code.

bzd2000 commented 5 years ago

This is the code calling the tag widget

class RecipeTags extends StatefulWidget {
  final Function onSave;
  final bool editable;

  final List<String> initValue;

  RecipeTags({@required this.onSave, this.initValue, this.editable});

  @override
  _RecipeTagsState createState() => _RecipeTagsState();
}

class _RecipeTagsState extends State<RecipeTags> {
  List<String> _tags = [];
  List<String> _suggestionsList = ["vlees", "vis", "pasta", "aardappel"];

  @override
  Widget build(BuildContext context) {
    print("build RecipeTags: $_tags");
    print("build RecipeTags widget.initValue: ${widget.initValue}");
    return Padding(
        padding: EdgeInsets.all(15.0),
        child:
            widget.editable ? buildInputTags(context) : buildSelectableTags());
  }

  buildInputTags(context) {
    return FormField<List<String>>(
        initialValue: widget.initValue,
        onSaved: widget.onSave,
        builder: (FormFieldState<List<String>> state) {
          return InputTags(
            tags: widget.initValue == null ? [] : widget.initValue,
            suggestionsList: _suggestionsList,
            onChange: (value) => state.didChange(value),
            onDelete: (value) {},
            onInsert: (value) {},
          );
        });
  }

  buildSelectableTags() {
    return SelectableTags(
        tags: widget.initValue == null ? [] : widget.initValue.map((title) => Tag(title: title)).toList() ,
        columns: 3, // default 4
        symmetry: true, // default false
        onPressed: (tag) {
          print(tag);
        });
  }

  @override
  void initState() {
    super.initState();
    print("add tags initState");
  }
}

And the display in selectableTags

  @override
  Widget build(BuildContext context)
  {

    _tags = widget.tags;
    print ('build  selectableTags $_tags');
    // essential to avoid infinite loop of addPostFrameCallback
    if(MediaQuery.of(context).orientation != _orientation || _width==0)
      _getwidthContainer();
    _orientation = MediaQuery.of(context).orientation;

    return Container(
      key:_containerKey,
      margin: EdgeInsets.symmetric(vertical:5.0,horizontal:0.0),
      color: widget.backgroundContainer ?? Colors.white,
      child: Column( children: _buildRow(), ),
    );
  }
Dn-a commented 5 years ago

@bzd2000 have you tried the latest version?

bzd2000 commented 5 years ago

@Dn-a , I'll give it a try

Dn-a commented 5 years ago

@bzd2000 solved?

Dn-a commented 5 years ago

@bzd2000 new version 0.4.2. check and leave feedback