I am looking for a Flutter Plugin to use in one of my POC projects. Idea is to create a dropdown field with a search option, something similar to what you can see on Yatra(dot)com.
It will be really helpful if someone can guide me to create a widget by myself to achieve this.
Any guidance is highly appreciated.
Have a look in this site and try out this code
Container(
child: DropdownSearch<String>(
mode: Mode.DIALOG,
showSearchBox: true,
searchBoxDecoration: InputDecoration(
filled: true,
fillColor: Colors.grey,
),
showAsSuffixIcons: true,
showClearButton: false,
dropdownButtonBuilder: (_) => Padding(
padding: const EdgeInsets.all(8.0),
child: const Icon(
Icons.arrow_drop_down,
size: 24,
color: Colors.red,
),
),
showSelectedItem: true,
items: ["bs", "test", "company"],
onChanged: (String newValue) {
setState(() {
// dropDownValue = newValue;
});
},
// selectedItem: dropDownValue,
),
),
Related
I am using the CupertinoSearchTextField in my app. It is working fine so far but I am missing one feature: the Cancel-Button.
In native iOS you can set to show the button which looks like this:
Does Flutter provide this functionality? I couldn't find it anywhere.
Clarification:
I don't mean the x/clear-button. I know that is build-in. What I mean is the actual Cancel-button which removes focus from the textField.
use Typeahead package.then in suffixIcon, you can add cancel feature to clear field.
TypeAheadField<String>(
hideOnEmpty: true,
minCharsForSuggestions: 2,
getImmediateSuggestions: true,
textFieldConfiguration: TextFieldConfiguration(
controller: cont_search,
cursorColor: Colors.grey,
textInputAction: TextInputAction.search,
decoration: InputDecoration(
//here the cancel button
suffixIcon: IconButton(
padding: EdgeInsets.fromLTRB(8, 4, 8, 8),
icon: Icon(Icons.clear),
onPressed: (){
cont_search.clear();
},
),
focusColor: Colors.black,
focusedBorder: InputBorder.none,
border: InputBorder.none,
//hintText: 'What are you looking for?',
icon: Icon(Icons.search),
),
onSubmitted: (value){
print("value taken is ${value}");
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => search_page(value)
));
}
),
suggestionsCallback: (String pattern) async {
return matches
.where((item) =>
item.toLowerCase().startsWith(pattern.toLowerCase()))
.toList();
},
itemBuilder: (context, String suggestion) {
return ListTile(
title: Text(suggestion),
);
},
onSuggestionSelected: (String suggestion) {
//push to page
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => search_page(suggestion)
));
print("Suggestion selected ${suggestion}");
},
)
If you wanna override x/clear-button's behaviour to unfocus the textfield, use this. Otherwise, you can put search textfield and a clear button in a row and implement button's behaviour like this. Problem solved.
onSuffixTap: (){
FocusScope.of(context).unfocus();
}
I ended up building it myself. I made use of the Focus-Widget and most important the AnimatedPadding. My code looks like this:
Row(
children: [
Flexible(
child: AnimatedPadding(
duration: const Duration(milliseconds: 100),
padding: EdgeInsets.only(right: _isSearching ? 50 : 0),
child: Focus(
onFocusChange: (hasFocus) {
setState(() {
_isSearching = hasFocus;
});
},
child: CupertinoSearchTextField(
placeholder: 'Suche'.tr,
controller: _textEditingController,
focusNode: _focusNode,
),
),
),
),
if (_isSearching)
Tappable(onTap: () {
dismissKeyboard();
}, builder: (context, isTapped) {
return AnimatedText(
text: 'Abbrechen',
isTapped: isTapped,
style: AppTextStyles.avenirNextH4Regular,
color: grey,
);
}),
],
),
I want to remove suffix icon from DropdownSearch widget. I am using dropdown_search plugin.
I have tried giving size to icon and also added visibility false. but any of these didn't work.
Even I have tried using dropdown builder too..!!
Please help..!!
DropdownSearch<String>(
dropdownBuilder: (context, str) {
return Text(str ?? "-");
},
dropdownDecoratorProps: DropDownDecoratorProps(
textAlign: TextAlign.left,
textAlignVertical: TextAlignVertical.center,
dropdownSearchDecoration: _appTheme.dropDownDecoration()),
dropdownButtonProps: const DropdownButtonProps(
alignment: Alignment.centerRight,
padding: EdgeInsets.all(0),
icon: SizedBox(
width: 0,
child: Visibility(
visible: false,
child: Icon(
Icons.arrow_downward,
size: 0,
)),
),
isVisible: false,
constraints: BoxConstraints(maxWidth: 0, maxHeight: 0),
iconSize: 0),
popupProps: PopupProps.menu(
textStyle: _appTheme.textFiledStyle,
showSelectedItems: true,
showSearchBox: true,
),
items: _registrationBloc.countries,
onChanged: (value) {
_registrationBloc.selectedCountry = value;
},
selectedItem: _registrationBloc.selectedCountry,
)
set the isVisible property to false it will work.
or you can use other plugin. one is searchfield which i have used.
There is a 'dropDownButton' property for DropdownSearch, use it as follows
dropDownButton : Container(),
hope it works
I m new to flutter, need help to set the value of the DropdownButton programmatically.
The value is from textfield. Once i click it, it will set the value at the dropdownbutton automatically.
Widget _districtListContainer() {
return Container(
width: 360.0,
child: new InputDecorator(
decoration: InputDecoration(
suffixIcon: new Icon(
Icons.search,
color: Colors.blue[700],
),
labelText: 'Select District',
labelStyle: TextStyle(fontSize: 12.0)),
isEmpty: _selectedDistrict == null,
child: new DropdownButtonHideUnderline(
child: new DropdownButton<District>(
value: _selectedDistrict,
isDense: true,
isExpanded: false,
onChanged: (District newValue) {
setState(() {
_selectedDistrict = newValue;
});
},
items: _listDistrict?.map((District value) {
return new DropdownMenuItem<District>(
value: value,
child: new Text(
value.district != null ? value.district : '',
style: new TextStyle(fontSize: 11.0),
),
);
})?.toList() ??
[],
),
),
),
margin: EdgeInsets.only(bottom: 10.0));
}
thanks
First Of All, Add the data into the list[] From the TextFormfield then retrieve the list into DropDownButton item.
Also, Make Sure, DropDown Button List Display Textformfield data insert activity could not be able to update simultaneously.
I am trying CarouselSlider.I want to make the upside Carousel Slider,bottom side TextFormField. I am holding a list of image paths in selected and send to the screen like this:
ElevatedButton(
onPressed: () {
Navigator.of(context).pushNamed(
OcrScreen.routeName,
arguments: {'image': selected},
);
},
After that I am taking arguments in other screen like this:
final args = ModalRoute.of(context)!.settings.arguments as Map;
final images=args['image'];
Later
I am putting this list into CarouselSlider:
return Scaffold(extendBodyBehindAppBar: false,
appBar: AppBar(
title: const Text('OCR'),
elevation: 0,
backgroundColor: Colors.transparent,
),
body:Column(children:[Container(
child: CarouselSlider(
options: CarouselOptions(),
items: images
.map((image) => Container(
child: Center(
child:
Image.file(File(image),fit: BoxFit.cover, width: 1000)),
))
.toList(),
)),TextFormField(
keyboardType: TextInputType.multiline,
controller: _titleController,
autofocus: false,
style: TextStyle(fontSize: 22.0, color: Colors.black),
maxLines: 20,
decoration: InputDecoration(
filled: true,
isDense: true,
contentPadding: new EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
fillColor: Colors.white,
))]
));
}
I am getting List is not a subtype of type List? error and I couldn't find the solution for this error can anyone help me to find a solution?
Seems like args['image'] can be null that's why you get this error because items should be of type List<Widget>. Try creating the variable this way.
final List<String> images = args['image'] ?? [];
However, you may want to check first if images.isNotEmpty beforing mapping it.
this is my code
Padding(
padding: EdgeInsets.symmetric(vertical: 10.h),
child: DropdownButtonFormField(
decoration: InputDecoration(
labelText: "countries",
labelStyle: TextStyle(fontSize: 16.sp),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10))),
items: const [
DropdownMenuItem(child: Text("USA"), value: "USA"),
DropdownMenuItem(
child: Text("Canada"), value: "Canada"),
DropdownMenuItem(
child: Text("Brazil"), value: "Brazil"),
DropdownMenuItem(
child: Text("England"), value: "England"),
],
),
),
when i click on DropDownButtonFormField the items does not appear .
A common mistake when it is not updating is to use DropdownButtonFormField in a StatelessWidget rather than a StatefulWidget. but hard to say as you did not share that part of the code
Seems you are also missing other code in your DropdownButtonFormField
DropdownButtonFormField(
value: myVariable,
onChanged: (value) {
setState(() {
myVariable= value;
});
},
Let me know if this does not help.
Anything with an interaction with user must be inside StatefulWidget.
There is another ways like changenotifier using notifyListeners() inside void function.
https://medium.com/#aruny3/how-to-use-changenotifier-in-flutter-440371617b8c