Skip to content

Commit

Permalink
Merge pull request akbarpulatov#29 from vcenturion/master
Browse files Browse the repository at this point in the history
- fix modal scrolling throws exception
  • Loading branch information
vasilich6107 authored Mar 3, 2024
2 parents e50edf4 + acfd715 commit 255367d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/src/choices_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'scrollbar.dart';

/// Choices list widget
class S2ChoicesList<T> extends StatelessWidget {
final scrollController = ScrollController();

/// the length of the choice list
final int itemLength;

Expand All @@ -18,7 +20,7 @@ class S2ChoicesList<T> extends StatelessWidget {
final S2ChoiceConfig config;

/// Default constructor
const S2ChoicesList({
S2ChoicesList({
Key? key,
required this.itemLength,
required this.itemBuilder,
Expand All @@ -31,6 +33,7 @@ class S2ChoicesList<T> extends StatelessWidget {
Widget result = NotificationListener<ScrollNotification>(
onNotification: (notification) => false,
child: Scrollbar(
controller: scrollController,
child: config.isWrapLayout
? _listWrap(context)
: config.isGridLayout
Expand All @@ -41,13 +44,12 @@ class S2ChoicesList<T> extends StatelessWidget {
),
);

return config.direction == Axis.horizontal
? Wrap(children: <Widget>[result])
: result;
return config.direction == Axis.horizontal ? Wrap(children: <Widget>[result]) : result;
}

Widget _listWrap(BuildContext context) {
return SingleChildScrollView(
controller: scrollController,
physics: config.physics,
scrollDirection: config.direction,
padding: config.padding ??
Expand All @@ -71,6 +73,7 @@ class S2ChoicesList<T> extends StatelessWidget {

Widget _listDefault() {
return ListView.builder(
controller: scrollController,
shrinkWrap: true,
physics: config.physics,
scrollDirection: config.direction,
Expand All @@ -82,6 +85,7 @@ class S2ChoicesList<T> extends StatelessWidget {

Widget _listSeparated() {
return ListView.separated(
controller: scrollController,
shrinkWrap: true,
physics: config.physics,
scrollDirection: config.direction,
Expand All @@ -94,6 +98,7 @@ class S2ChoicesList<T> extends StatelessWidget {

Widget _listGrid() {
return GridView.builder(
controller: scrollController,
shrinkWrap: true,
physics: config.physics,
scrollDirection: config.direction,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/widget/s2_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,12 @@ abstract class S2State<T> extends State<SmartSelect<T>> {

/// Returns the grouped choice items widget
Widget groupedChoices(List<S2Group<T>> groups) {
final scrollController = ScrollController();

return Scrollbar(
controller: scrollController,
child: ListView.builder(
controller: scrollController,
itemCount: groups.length,
itemBuilder: (_, int i) {
return customGroup(groups[i]) ?? defaultGroup(groups[i]);
Expand Down

0 comments on commit 255367d

Please sign in to comment.