GithubHelp home page GithubHelp logo

Comments (7)

JRamos29 avatar JRamos29 commented on May 25, 2024 2

@rayad I created this gist where you can see the code with examples.

I created a flag enabledSuggestions that must be set to false if you don't want to use suggestions.

At the example using object the ideal it's to use a form or a dialog where the user can set the object attributes.
The code need some adjusts, but for the purpose of add chips it's working.

You need replace the chip_input.dart with the custom_chip_input.dart (this file use other files from the original flutter_chips_input package if you need to use the suggestions).

from flutter_chips_input.

JRamos29 avatar JRamos29 commented on May 25, 2024 1

I was looking for this also. Any idea of when will be implemented?

As workaround i changed the ChipInput class with the addEntryBuilder, and the result its something like this. The text its typed directly in the chip. Needs adjusts, but its just an idea while the package doesn't releases this feature. Hope it helps.

...
typedef EntryBuilder<T> = Widget Function(
    BuildContext context, CustomChipsInputState<T> state);

class ChipsInput<T> extends StatefulWidget {
  ChipsInput({
 ...
    this.addEntryBuilder,
 ...   
  })  : assert(maxChips == null || initialValue.length <= maxChips),
        super(key: key);

 ...  
  final EntryBuilder<T> addEntryBuilder;
 ...  
  @override
  ChipsInputState<T> createState() => ChipsInputState<T>(textOverflow);
}

class ChipsInputState<T> extends State<ChipsInput<T>>
    implements TextInputClient {
 
 ...  
  void addChip(T data) {
    if (widget.enabled) {
      setState(() {
        _chips.add(data);
        _updateTextInputState();
      });
      _initFocusNode();
      widget.onChanged(_chips.toList(growable: false));
    }
  }

 ...  

  @override
  Widget build(BuildContext context) {
    var chipsChildren = _chips
        .map<Widget>((data) => widget.chipBuilder(context, this, data))
        .toList();

    final theme = Theme.of(context);

    chipsChildren.add(
      Container(
        height: 32.0,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            // Flexible(
            //   flex: 1,
            //   child: Text(
            //     text,
            //     maxLines: 1,
            //     overflow: this.textOverflow,
            //     style: widget.textStyle ??
            //         theme.textTheme.subhead.copyWith(height: 1.5),
            //   ),
            // ),
            Container(child: widget.addEntryBuilder(context, this)),
            Flexible(
              flex: 0,
              child: _TextCaret(
                resumed: _focusNode.hasFocus,
              ),
            ),
          ],
        ),
      ),
    );

 ...  
   
}

And in my page i used the addEntryBuilder like this:

 addEntryBuilder: (context, state) {
                  AppProfile newProfile = AppProfile(state.text, 'email',
                      'https://upload.wikimedia.org/wikipedia/commons/7/7c/Profile_avatar_placeholder_large.png');

                  if (state.text != null) {
                    return InputChip(
                      key: ObjectKey(newProfile),
                      label: Text(state.text),
                      avatar: CircleAvatar(
                        backgroundImage: NetworkImage(newProfile.imageUrl),
                      ),
                      onPressed: () => state.addChip(newProfile),
                      materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                    );
                  } else {
                    return Text('');
                  }
                },

from flutter_chips_input.

danvick avatar danvick commented on May 25, 2024 1

Hi @appstute-pratik,
At this point in time, the easiest way to add a chip programmatically is by use of a GlobalKey. Like so:

GlobalKey<ChipsInputState> _chipKey = GlobalKey();
...
ChipsInput(
    key: _chipKey,
    ...
),
_chipKey.currentState.selectSuggestion(chip);
....

from flutter_chips_input.

danvick avatar danvick commented on May 25, 2024

This is a great suggestion.

I'll do my best to implement this.

from flutter_chips_input.

appstute-pratik avatar appstute-pratik commented on May 25, 2024

@danvick Any work around?

from flutter_chips_input.

danvick avatar danvick commented on May 25, 2024

Sorry for the delay on this guys. Using a ChipsController as I'm planning to will create quite a bit of breaking changes, hence I'm working on this in version 2 of the package which is still in the press.

The reason for the delay is that my schedule is a bit rigid with work stuff (and other opensource projects I'm working on) that I find it hard to react quickly to matters.

Thanks for your understanding, guys.

from flutter_chips_input.

rayad avatar rayad commented on May 25, 2024

this

Do you have a complete solution for this? I am struggling to implement the same. I need to make http request to database and if data not found then add new.

from flutter_chips_input.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.