bs_flutter_selectbox

Creator: coderz1093

Last updated:

0 purchases

bs_flutter_selectbox Image
bs_flutter_selectbox Images

Languages

Categories

Add to Cart

Description:

bs flutter selectbox

Bs Flutter Select Box #
Web HTML select option with serverside

Feature:

Select option with server side data
Searchable select option
Multiple select option
Select label

This plugin is the best alternative for select2 library
Getting Started #
Add the dependency in pubspec.yaml:
dependencies:
...
bs_flutter: any
copied to clipboard
Select Box #
Example: main.dart
To create a select box you need to import:
import 'package:bs_flutter_selectbox/bs_flutter_selectbox.dart';
copied to clipboard
After create controller:
// ...
BsSelectBoxController _select1 = BsSelectBoxController(
options: [
BsSelectBoxOption(value: 1, text: Text('1')),
BsSelectBoxOption(value: 2, text: Text('2')),
BsSelectBoxOption(value: 3, text: Text('3')),
]
);
// ...
copied to clipboard
After all is done copy the code below:
// ...
BsSelectBox(
hintText: 'Pilih salah satu',
selectBoxController: _select1,
),
// ...
copied to clipboard

If you need to customize size and style, use properties style and size. And create your custom size with class BsSelectBoxSize or BsSelectBoxStyle to custom style
static const BsSelectBoxSize customSize = BsSelectBoxSize(
fontSize: 14.0,
optionFontSize: 14.0,
searchInputFontSize: 14.0,
labelX: 15.0,
labelY: 13.0,
transitionLabelX: -15.0,
transitionLabelY: 5.0,
padding: EdgeInsets.only(left: 15.0, right: 15.0, top: 12.0, bottom: 12.0)
);
copied to clipboard
static const BsSelectBoxStyle outline = BsSelectBoxStyle(
borderRadius: BorderRadius.all(Radius.circular(5.0))
);
copied to clipboard
Note #

labelX and labelY is used to set label position if using hintTextLabel
transitionLabelX and transitionLabelY is used to set label position if using hintTextLabel when have selected value
BsSelectBoxStyle have properties borderRadius, color, placeholderColor, selectedBackgroundColor, selectedColor, disabledBackgroundColor, backgroundColor, borderColor, fontSize, arrowIcon

Select Box Style 2 (hintTextLabel) #
Select box using hintTextLabel
// ...
BsSelectBox(
hintTextLabel: 'Pilih salah satu',
selectBoxController: _select1,
),
// ...
copied to clipboard

Select Box Multiple #
To create a select box with multiple allowed set multiple properties in BsSelectBoxController to true:
// ...
BsSelectBoxController _select2 = BsSelectBoxController(
multiple: true,
options: [
BsSelectBoxOption(value: 1, text: Text('1')),
BsSelectBoxOption(value: 2, text: Text('2')),
BsSelectBoxOption(value: 3, text: Text('3')),
BsSelectBoxOption(value: 4, text: Text('4')),
BsSelectBoxOption(value: 5, text: Text('5')),
BsSelectBoxOption(value: 6, text: Text('6')),
]
);
// ...
copied to clipboard
Note #

To get selected value use getSelected or getSelectedAll
If you need returned string use getSelectedAsString, it will be returned string value with , separator
To set selected value use setSelected or setSelectedAll


Select Box Server Side #
To create a select box with server side data, use serverSide property
BsSelectBox(
hintText: 'Pilih salah satu',
searchable: true,
selectBoxController: _select3,
serverSide: selectApi,
)
copied to clipboard
Note #

To enable searchable option, set searchable property true
serverSide property need returned Future<BsSelectBoxResponse>

selectApi function
// ...
Future<BsSelectBoxResponse> selectApi(Map<String, String> params) async {
Uri url = Uri.http('localhost', 'api-json.php', params);
Response response = await http.get(url);
if(response.statusCode == 200) {
List json = convert.jsonDecode(response.body);
return BsSelectBoxResponse.createFromJson(json);
}

return BsSelectBoxResponse(options: []);
}
// ...
copied to clipboard
Json response data
[
{
"value":"1",
"text":"Tipe 01",
"typecd":"TP01"},
{
"value":"2",
"text":"Type 02",
"typecd":"TP02"
}
]
copied to clipboard
Note #

createFromJson is automatically put response data value, but you cant change it with define manual
If you want to make typecd as value of option, use value parameters of createFromJson

/// ...
if(response.statusCode == 200) {
List json = convert.jsonDecode(response.body);
return BsSelectBoxResponse.createFromJson(json,
value: (data) => data['typecd'],
);
}
/// ...
copied to clipboard

If you want to make typecd as text of option, use renderText parameters of createFromJson
renderText function need returned Widget

/// ...
if(response.statusCode == 200) {
List json = convert.jsonDecode(response.body);
return BsSelectBoxResponse.createFromJson(json,
value: (data) => data['typecd'],
renderText: (data) => Text(data['typecd'])
);
}
/// ...
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.