TextField Widget with emoji flutter - flutter

How can I open keyboard type == emoji. Not number, not letter, just emoji. Without using emoji_picker package

To open the emoji container emoji_picker
Create A method emojiContainer
emojiContainer() {
return EmojiPicker(
bgColor: Colors.red,
indicatorColor: Colors.blue,
rows: 3,
columns: 7,
onEmojiSelected: (emoji, category) {
setState(() {
isWriting = true;
});
textFieldController.text = textFieldController.text + emoji.emoji;
},
recommendKeywords: ["face", "happy", "party", "sad"],
numRecommended: 50,
);
}
And use an onPressed
onPressed: () {
if (!showEmojiPicker) {
// keyboard is visible
hideKeyboard();
showEmojiContainer();
} else {
//keyboard is hidden
showKeyboard();
hideEmojiContainer();
}
},

Related

How can make checkbox select and multiple selection with Getx

my code is without button that make select all
View class
GetBuilder<ProductController>(
builder: (controller) {
return
Container(
height: 50,
child: Transform.scale(
scale: 1.2,
child: Checkbox(
activeColor: MyThemes.yellow,
shape:RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)
),
splashRadius: 18.8,
value: controller.items[index]["check"],
onChanged:((value) {
controller.CheckBrand(index, value);
}
)),
),
);}),
controller class
RxList<Map<String,dynamic>> items = [{"one": "Item1", "check": false},
{"one": "Item2", "check": false}, {"one": "Item3", "check": false}].obs;
CheckBrand(index, ischeck){ items[index]["check"]=ischeck; update(); }
I want to ask is there another way to make checkbox selection and how can I make select all button for this items
you can iterate over elements to check them all at once, you can use this method:
void checkAll({bool newValue = true}) {
items.value.forEach((element) {
element["check"] = newValue;
});
update();
}
I will add also a method that uncheck all at once:
void unCheckAll() {
checkAll(newValue: false);
}
now from your view, just call it like this:
controller.checkAll(); // will check all check boxes
controller.unCheckAll(); // will uncheck all check boxes

How to remove elements if they match in List?

When I click on the button, I need its name to be added to the List and when the button is clicked again, its name is added to the List again, but if 2 names match in the List, then they both need to be deleted. I tried to implement through the for loop but it does not work correctly for me. Tell me how can this be done?
function
List<String> types = [];
void reportButton(int number, String type) {
reportsList[number] = !reportsList[number];
if (reportsList.contains(true)) {
isEnabledC = true;
} else {
isEnabledC = false;
}
types.add(type);
for (var element in types) {
if (element == type) {
types.removeWhere((element) => element == type);
}
}
buttons
SizedBox(
width: size.width / 3,
child: GestureDetector(
onTap: () {
cubit.reportButton(0, 'comment');
// state.type = 'comment';
},
child: ReportButton(
enabled: state.reports[0],
svg: constants.Assets.comment,
text: 'Comment',
),
),
),
SizedBox(
width: size.width / 3,
child: GestureDetector(
onTap: () {
cubit.reportButton(1, 'broken');
// state.type = 'broken';
},
child: ReportButton(
enabled: state.reports[1],
svg: constants.Assets.attention,
text: 'Broken station',
),
),
),
you do not have to loop through the list of string. You can simply check if the list contains the string. If yes, remove it, else add the string
List<String> types = ["apple", "ball", "cat", "dog"];
void main() async {
reportButton(1, "xyz");
}
void reportButton(int number, String type) {
if (types.contains(type)) {
types.removeWhere((element) => element == type);
} else {
types.add(type);
}
print(types);
}
List<String> types = ["boy", "girl", "father", "hog"];
void main() {
reportButton(1, "xyz");
}
void reportButton(int number, String type) {
if (types.contains(type)) {
types.removeWhere((element) => element == type);
}else {
types.add(type);
}
print(types);
}

Flutter parse emoji selected to textfield

I have an emoji-selector that works perfectly, but I would like to parse the emoji selected to TextField in Flutter. Below I have below my TextField and Emoji Selector.
Widget buildSticker() {
return EmojiPicker(
rows: 10,
columns: 5,
buttonMode: ButtonMode.MATERIAL,
recommendKeywords: ["racing", "horse","Face","Ghost"],
numRecommended: 10,
onEmojiSelected: (emoji, category) {
print(emoji);
},
);
}
I want the emoji picker to display on the TextField below:
TextField(
controller: _controllerComment,
keyboardType: TextInputType.multiline,
maxLines: null,
),
My emoji return it print as : Upside-Down Face, Emoji: 🙃
Add emoji into _controllerComment like this using emoji_picker_flutter,
onEmojiSelected: (category, emoji) {
setState(() {
_controllerComment.text = _controllerComment.text + emoji.emoji;
});
},

How to prevent the progress indicator to appear again when clicking the selected widget

There are two FilterChips and clicking the selected one will open the progress indicator again. So every time I click on the FilterChip already selected it calls the controller again and the progress indicator returns.
I want nothing to happen when the selected one is clicked but I don't understand the logic.
Also api1Type must be come always true. And loadingController calling progress indicator.
Filter Controller
var filterTypeNumb = 0;
var filterList = [].obs;
RxBool api1Type = true.obs;
RxBool api2Type = false.obs;
void getFilterType() {
if (filterTypeNumb == 0) {
filterList(api1Controller.api1List);
api1Type(true);
api2Type(false);
loadingController2Sec.getLoading();
} else if (filterTypeNumb == 1) {
filterList(api2Controller.api2List);
api1Type(false);
api2Type(true);
loadingController2Sec.getLoading();
}
}
#override
void onInit() {
getFilterType();
super.onInit();
}
}
Filter Chip
FilterTypeController filterTypeController = Get.put(FilterTypeController());
FilterChip(
label: Text(
"Filter 1",
style: fAppNavBarTextStyle,
),
checkmarkColor: Colors.white,
selectedColor: cButtonColor,
backgroundColor: const Color(0xFF878787),
selected:
filterTypeController.api1Type.value,
onSelected: (bool value) {
filterTypeController.filterTypeNumb = 0;
value =
filterTypeController.api1Type.value;
filterTypeController.getFilterType();
//Get.back();
}),
FilterChip(
label: Text(
"Filter 2",
style: fAppNavBarTextStyle,
),
selectedColor: cGetFreeColor,
backgroundColor: const Color(0xFF878787),
selected:
filterTypeController.api2Type.value,
onSelected: (bool value) {
filterTypeController.filterTypeNumb = 1;
value =
filterTypeController.api2Type.value,
filterTypeController.getFilterType();
//Get.back();
}),

Left and right to cancel or confirm slider flutter

I need to use a slider which slides both to the left to cancel and right to confirm
this is the desired slider
I couldn't find a way to do it, is there any way to do it ?
You can achieve it by using a Slider and customizing it.
...
double _currentSliderValue = 5;
Slider customSlider() {
return Slider(
value: _currentSliderValue,
min: 0,
max: 10,
divisions: 10,
onChanged: (double value) {
setState(() {
_currentSliderValue = value;
});
if (_currentSliderValue == 0) // Decline
else if (_currentSliderValue == 10) // Accept
else // Nothing
},
);
}
The UI can be achieved by including the customSlider() as a child of a Row widget as follows (didn't try it but it should be the right path):
Row declineOrAcceptSlider() {
return Row(children: [
Text("Decline"),
customSlider(),
Text("Accept")
], mainAxisAlignment: MainAxisAlignment.spacedEvenly);
}
Use Gesture Detector this
Example :
#override
Widget build(BuildContext context) {
String swipeDirection;
return GestureDetector(
onPanUpdate: (details) {
swipeDirection = details.delta.dx < 0 ? 'left' : 'right';
},
onPanEnd: (details) {
if (swipeDirection == 'left') {
//handle swipe left event
}
if (swipeDirection == 'right') {
//handle swipe right event
}
},
child: //child widget
);
}