-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sel value programmability #21
Comments
Fix like this void _updateSelectedIndex() {
} @OverRide |
Can this change please be made as it will greatly help with setting initial values. Currently the initial value set does not work when rebuilding a the widget |
Hello @lechuk and @ettiennelr , Thanks for your feedback. ...
String preselectedValue="dolor sit";
...
"Initial value issue21": SearchableDropdown(
items: items,
value: preselectedValue,
hint: Text('Select One'),
searchHint: new Text(
'Select One',
style: new TextStyle(fontSize: 20),
),
onChanged: (value) {
setState(() {
selectedValue = value;
});
},
isExpanded: true,
),
... The result is as expected that the selected value is "dolor sit". Could it be that you are not using the latest version of the plugin? |
Hi @lechuk Thanks for the quick response and btw i LOVE your work on this widget!! The problem I am experiencing is that I change value on my SearchableDropdown after it was created the first time due to it being reused in a dependent manner. What I have noticed is that your logic for value gets done inside initState. So if I try and change it again after the first time to another value the change does not get applied. It then causes index error and value does not display as default before opening drop down again. Hoped this explains it well? |
Here is just an example to test.
2 lookups both using String selectedValue;
So once I have selectedValue on the first lookups the seconds lookup must
now default to it. But it does not. value: selectedValue gets ignored.
Thanks :)
import 'package:flutter/material.dart';
import 'package:searchable_dropdown/searchable_dropdown.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@OverRide
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String selectedValue;
@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new SearchableDropdown.single(
onClear: () {
setState(() {
selectedValue = null;
});
},
searchFn: (String keyword, items) {
List<int> ret = List<int>();
if (keyword == null || keyword.isEmpty) {
ret = Iterable<int>.generate(items.length).toList();
}
if (keyword != null && items != null && keyword.isNotEmpty) {
keyword.split(" ").forEach((k) {
int i = 0;
items.forEach((item) {
if (k.isNotEmpty &&
(item.value.toString().toLowerCase().contains(k.toLowerCase()))) {
ret.add(i);
}
i++;
});
});
}
return (ret);
},
items: ["ONE", "TWO",
"THREE"].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Container(
alignment: AlignmentDirectional.centerEnd,
child: Text(value.trim(), overflow:
TextOverflow.ellipsis, textAlign: TextAlign.right),
),
);
}).toList(),
value: selectedValue,
onChanged: (value) {
setState(() {
selectedValue = value;
});
},
isExpanded: true,
),
new SearchableDropdown.single(
onClear: () {
setState(() {
selectedValue = null;
});
},
searchFn: (String keyword, items) {
List<int> ret = List<int>();
if (keyword == null || keyword.isEmpty) {
ret = Iterable<int>.generate(items.length).toList();
}
if (keyword != null && items != null && keyword.isNotEmpty) {
keyword.split(" ").forEach((k) {
int i = 0;
items.forEach((item) {
if (k.isNotEmpty &&
(item.value.toString().toLowerCase().contains(k.toLowerCase()))) {
ret.add(i);
}
i++;
});
});
}
return (ret);
},
items: ["ONE",
"TWO"].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Container(
alignment: AlignmentDirectional.centerEnd,
child: Text(value.trim(), overflow:
TextOverflow.ellipsis, textAlign: TextAlign.right),
),
);
}).toList(),
value: selectedValue,
onChanged: (value) {
setState(() {
selectedValue = value;
});
},
isExpanded: true,
)
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
…On Sat, Mar 14, 2020 at 5:21 PM lcuis ***@***.***> wrote:
Hello @lechuk <https://github.com/lechuk> and @ettiennelr
<https://github.com/ettiennelr> ,
Thanks for your feedback.
I am able to set the initial value as follows in the example app:
...
String preselectedValue="dolor sit";
...
"Initial value issue21": SearchableDropdown(
items: items,
value: preselectedValue,
hint: Text('Select One'),
searchHint: new Text(
'Select One',
style: new TextStyle(fontSize: 20),
),
onChanged: (value) {
setState(() {
selectedValue = value;
});
},
isExpanded: true,
),
...
The result is as expected that the selected value is "dolor sit".
Could it be that you are not using the latest version of the plugin?
Because I seem to recognize an old version of the _updateSelectedIndex()
function which doesn't exist anymore.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#21 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB6J755OUHJW33YBQJ26YGDRHOOHLANCNFSM4LCBEB2Q>
.
|
Hello @ettiennelr , Thanks for your explanations. I think I was able to reproduce your issue within the latest plugin: ...
String preselectedValue="dolor sit";
...
@override
Widget build(BuildContext context) {
Map<String, Widget> widgets;
widgets = {
...
"Update value from elsewhere issue21": Column(
children: [
SearchableDropdown(
items: items,
value: selectedValue,
hint: Text('Select One'),
searchHint: new Text(
'Select One',
style: new TextStyle(fontSize: 20),
),
onChanged: (value) {
setState(() {
selectedValue = value;
});
},
isExpanded: true,
),
FlatButton(
child: Text("Select $preselectedValue"),
onPressed: () {
setState(() {
selectedValue = preselectedValue;
});
},
),
],
),
... Indeed, pressing the new button doesn't set the value at least on the screen. |
Fantastic
Thanks
…On Sat, 14 Mar 2020, 18:27 lcuis, ***@***.***> wrote:
Hello @ettiennelr <https://github.com/ettiennelr> ,
Thanks for your explanations. I think I was able to reproduce your issue
within the latest plugin:
...
String preselectedValue="dolor sit";
...
@OverRide
Widget build(BuildContext context) {
Map<String, Widget> widgets;
widgets = {
...
"Update value from elsewhere issue21": Column(
children: [
SearchableDropdown(
items: items,
value: selectedValue,
hint: Text('Select One'),
searchHint: new Text(
'Select One',
style: new TextStyle(fontSize: 20),
),
onChanged: (value) {
setState(() {
selectedValue = value;
});
},
isExpanded: true,
),
FlatButton(
child: Text("Select $preselectedValue"),
onPressed: () {
setState(() {
selectedValue = preselectedValue;
});
},
),
],
),
...
Indeed, plressing the new button doesn't set the value at least on the
screen.
I will check your example and whether there is a solution.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#21 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB6J7552QSVQXVFGDAD6UXTRHOV5PANCNFSM4LCBEB2Q>
.
|
Thank you very much @ettiennelr and @lechuk ! Indeed, calling a restored I hope this solves your issues! Thanks again! |
thanks so much.
When do you expect this to be released?
…On Sun, Mar 15, 2020 at 5:33 AM lcuis ***@***.***> wrote:
Thank you very much @ettiennelr <https://github.com/ettiennelr> and
@lechuk <https://github.com/lechuk> !
Indeed, calling a restored _updateSelectedIndex() function from the
didUpdateWidget function allows update of the selected value from outside
the widget.
So, I just applied the solution provided by @lechuk
<https://github.com/lechuk> .
The only issues were regressions with the "select all" and "select none"
examples which are corrected by using the selectedItems instead of the
selectedItemsClose.
Automated tests pass.
I created PR #26
<#26> for the
correction and asked @icemanbsi <https://github.com/icemanbsi> for review
before he may publish to pub.dev .
My version of the plugin <http:///lcuis/search_choices> was also
affected. I applied the same correction and published to pub.dev
<https://pub.dev/packages/search_choices> through CD.
I hope this solves your issues!
Thanks again!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#21 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB6J7565GQAIVDKHFKSAEETRHREATANCNFSM4LCBEB2Q>
.
|
My pleasure @ettiennelr . |
Hi All
Tried to create a multi select drop down using example. Seems to not work.
See my code below
import 'package:flutter/material.dart';
import 'package:search_choices/search_choices.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@OverRide
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String selectedValue;
List<int> selectedItems;
@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new SearchChoices.multiple(
selectedItems: selectedItems,
closeButton: (selectedItemsClose) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RaisedButton(
onPressed: () {
setState(() {
selectedItemsClose.clear();
selectedItemsClose.addAll(Iterable<int>.generate(3).toList());
});
},
child: Text("Select all")),
RaisedButton(
onPressed: () {
setState(() {
selectedItemsClose.clear();
});
},
child: Text("Select none")),
],
);
},
onClear: () {
setState(() {
selectedValue = null;
});
},
searchFn: (String keyword, items) {
List<int> ret = List<int>();
if (keyword == null || keyword.isEmpty) {
ret = Iterable<int>.generate(items.length).toList();
}
if (keyword != null && items != null && keyword.isNotEmpty) {
keyword.split(" ").forEach((k) {
int i = 0;
items.forEach((item) {
if (k.isNotEmpty &&
(item.value.toString().toLowerCase().contains(k.toLowerCase()))) {
ret.add(i);
}
i++;
});
});
}
return (ret);
},
items: ["ONE", "TWO",
"THREE"].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Container(
alignment: AlignmentDirectional.centerEnd,
child: Text(value.trim(), overflow:
TextOverflow.ellipsis, textAlign: TextAlign.right),
),
);
}).toList(),
onChanged: (value) {
setState(() {
selectedItems = value;
});
},
isExpanded: true,
),
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
…On Sun, Mar 15, 2020 at 9:48 AM lcuis ***@***.***> wrote:
My pleasure @ettiennelr <https://github.com/ettiennelr> .
For the release, this is already published for search_choices
<https://pub.dev/packages/search_choices> and for searchable_dropdown,
this depends on @icemanbsi <https://github.com/icemanbsi> as I cannot
publish for him.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#21 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB6J756Y4IQG5SDCG426T2TRHSB27ANCNFSM4LCBEB2Q>
.
|
Hello @ettiennelr , I believe that with the newer example, the onPressed functions should use selectedItems instead of selectedItemsClosed and selectedItems should be initialized as []. Thanks for reporting this! |
Hi @ettiennelr , Thanks again for raising this concern! Here is a working example based on yours when using the latest version of search_choices: import 'package:flutter/material.dart';
import 'package:search_choices/search_choices.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<int> selectedItems = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new SearchChoices.multiple(
selectedItems: selectedItems,
closeButton: (selectedItemsClose, closeContext, Function updateParent) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RaisedButton(
onPressed: () {
setState(() {
selectedItemsClose.clear();
selectedItemsClose.addAll(Iterable<int>.generate(3).toList());
});
updateParent(selectedItemsClose);
},
child: Text("Select all")),
RaisedButton(
onPressed: () {
setState(() {
selectedItemsClose.clear();
});
updateParent(selectedItemsClose);
},
child: Text("Select none")),
],
);
},
searchFn: (String keyword, items) {
List<int> ret = List<int>();
if (keyword == null || keyword.isEmpty) {
ret = Iterable<int>.generate(items.length).toList();
}
if (keyword != null && items != null && keyword.isNotEmpty) {
keyword.split(" ").forEach((k) {
int i = 0;
items.forEach((item) {
if (k.isNotEmpty &&
(item.value.toString().toLowerCase().contains(k.toLowerCase()))) {
ret.add(i);
}
i++;
});
});
}
return (ret);
},
items: ["ONE", "TWO",
"THREE"].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Container(
alignment: AlignmentDirectional.centerEnd,
child: Text(value.trim(), overflow:
TextOverflow.ellipsis, textAlign: TextAlign.right),
),
);
}).toList(),
onChanged: (value) {
setState(() {
selectedItems = value;
});
},
isExpanded: true,
),
],
),
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
} I am not certain why the update was not happening in your case. Maybe because it is not in tabs. It would be interesting to test with searchable_dropdown which doesn't have the updateParent method. Anyway, sorry for the inconvenience @ettiennelr and I hope this solves your issue. |
Corrected issue #21 to allow selection update from outside the plugin
I can't set selected value programmability
The text was updated successfully, but these errors were encountered: