Comments (7)
@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.
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.
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.
This is a great suggestion.
I'll do my best to implement this.
from flutter_chips_input.
@danvick Any work around?
from flutter_chips_input.
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.
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)
- Delay between typing text and getting a suggestion
- Compiler error after upgrading to Flutter 2.13.0-0.2.pre (Beta channel) HOT 1
- Error in TextInputClient for flutter 3 HOT 6
- Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null
- After version 2.0.0 can only enter a single character HOT 2
- Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- Cannot delete the initial value with normal delete button keyboard HOT 1
- Error on showing chips when adding suffix or prefix icons
- Is there a way to add the user input value even if the value is not found. HOT 2
- Changing background of the input area
- Keyboard backspace not registered HOT 1
- add in readme
- write @ then complete HOT 1
- How to not dismiss the suggestion list while choosing many suggestion at a time
- ChipsInputState missing performSelector override
- Add "@" as a char HOT 1
- Move this repository to Flutter form builder ecosystem HOT 1
- Not able to add more than 1 character and backspace also not working in samsung devices using samsung default keyboard. HOT 2
- Not compatible with flutter 3.7 HOT 22
- Hello, how to make the textEditController selection to the end when addeda WidgetSpan
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_chips_input.