Skip to content
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

Erro => scrollDirection: Axis.horizontal #13

Closed
MarceloRab opened this issue Sep 7, 2019 · 16 comments · Fixed by #14
Closed

Erro => scrollDirection: Axis.horizontal #13

MarceloRab opened this issue Sep 7, 2019 · 16 comments · Fixed by #14
Labels
bug Something isn't working

Comments

@MarceloRab
Copy link

The following NoSuchMethodError was thrown building _StickySliverListItem(dependencies:
I/flutter (31517): [MediaQuery], state: _StickySliverListItemState#030fb):
I/flutter (31517): The method 'addListener' was called on null.
I/flutter (31517): Receiver: null
I/flutter (31517): Tried calling: addListener(Closure: () => void from Function 'markNeedsPaint':.)

@TatsuUkraine
Copy link
Owner

@MarceloRab could you provide code sample?

@MarceloRab
Copy link
Author

class MyEvestsListDayScroll extends StatefulWidget {

@OverRide
_MyEvestsListDayScrollState createState() => _MyEvestsListDayScrollState();
}

class MyEvestsListDayScrollState extends State {
final String className = "
_MyEvestsListDayScrollState ___ ... ";
int minCount = 0;
int maxCount = 1;
CompromissoBloc _compromissoBloc;

//DateTime dayEvents;

@OverRide
void initState() {
//maxCount = widget.listEventDay.length;
//maxCount = _compromissoBloc.eventsDay.length;
_compromissoBloc = HomeModule.to.bloc();

super.initState();

}

@OverRide
Widget build(BuildContext context) {

return StreamBuilder<DateTime>(
    stream: _compromissoBloc.dayEscolhidoStream,
    builder: (context, snapshot) {
      if (!snapshot.hasData)
        return Center(
          child: CircularProgressIndicator(),
        );
      else
        return InfiniteList(
            // scrollDirection: Axis.horizontal,
            minChildCount: minCount,
            maxChildCount: maxCount,
            anchor: 0.0,
            builder: (BuildContext context, int index) {
              return InfiniteListItem(
                initialHeaderBuild: true,
                minOffsetProvider: (StickyState<int> state) => 50,
                //headerAlignment: HeaderAlignment.bottomLeft,
                headerStateBuilder:
                    (BuildContext context, StickyState<int> state) {
                  return Container(
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      color: Colors.orange.withOpacity(state.position != 0
                          ? 1 - (state.position)
                          : (1 - state.position).abs()),
                      boxShadow: [
                        BoxShadow(
                            color: Colors.black12,
                            blurRadius: 2,
                            offset: Offset(2.0, 3.0),
                            spreadRadius: 2.0)
                      ],
                    ),
                    alignment: Alignment.center,
                    margin: EdgeInsets.only(left: 6, top: 20),
                    padding: EdgeInsets.all(12),
                    width: 70,
                    height: 80,
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        Text(
                          //"${MyDateHelper.setDiaDate(_compromissoBloc.eventsFullList[index].id)}",
                          "${MyDateHelper.setDiaDate(snapshot.data)}",
                          style: TextStyle(
                              fontSize: 20,
                              fontFamily: 'Roboto Mono',
                              fontWeight: FontWeight.bold),
                        ),
                        Text(
                          //"${MyDateHelper.setDiaDate(_compromissoBloc.eventsFullList[index].id)}",

                          "${MyDateHelper.setMonthCalendar(
                            date: snapshot.data,
                          ).substring(0, 3)}",

                          style: TextStyle(
                            fontSize: 18,
                            fontFamily: 'Roboto Mono',
                          ),
                        ),
                      ],
                    ),
                  );
                },
                contentBuilder: (BuildContext context) {
                  return Container(
                    decoration: BoxDecoration(
                      color: Colors.blueAccent,
                        borderRadius: BorderRadius.all(
                            Radius.circular(20))),
                    height:
                        (34 * _compromissoBloc.eventsDay.length).toDouble(),
                    margin: EdgeInsets.only(left: 50, top: 10, right: 10),
                    width: MediaQuery.of(context).size.width - 60,
                    child: Align(
                      alignment: Alignment.topLeft,
                      child: Column(
                        //mainAxisSize: MainAxisSize.min,
                        mainAxisAlignment: MainAxisAlignment.start,

                        children:
                            _compromissoBloc.eventsDay.map<Widget>((event) {
                          return Container(
                            margin: EdgeInsets.only(left: 40, top: 10),
                            child: Text(
                              "Content ${event as String}",
                              style: TextStyle(
                                  color: Colors.white, fontSize: 18),
                            ),
                          );
                        }).toList(),
                      ),
                    ),
                  );
                },
              );
            });
    });

}
}

@MarceloRab
Copy link
Author

MarceloRab commented Sep 7, 2019

Thanks in advance for the support.

I commented on the part where the error occurs. => scrollDirection: Axis.horizontal.

Could you share an example where - scrollDirection: Axis.horizontal is used?

I am Brazilian.

@TatsuUkraine
Copy link
Owner

@MarceloRab sure - https://github.com/TatsuUkraine/flutter_sticky_infinite_list_example this is an example app, you can switch horizontal and vertical list there in left sidenav

@MarceloRab
Copy link
Author

MarceloRab commented Sep 7, 2019

Thank you. I'm going to study and ask for help if you need it.

Congratulations for the good work.

@TatsuUkraine
Copy link
Owner

TatsuUkraine commented Sep 7, 2019

@MarceloRab btw, I noticed that you going to render just 1 element with a bunch of data inside, so you can try to use just SingleChildScrollView with this widget inside https://github.com/TatsuUkraine/flutter_sticky_infinite_list/blob/master/lib/widget.dart#L363

https://github.com/TatsuUkraine/flutter_sticky_infinite_list#need-more-override-ok-not-tested

@MarceloRab
Copy link
Author

MarceloRab commented Sep 7, 2019

That's right, I'm in testing mode. Already tested with many elements and in vertical mode flowed correctly.

The above error also occurred with too many elements. But I need to study the above example in more detail.

@TatsuUkraine
Copy link
Owner

@MarceloRab btw, could you also provide flutter doctor info?

@MarceloRab
Copy link
Author

MarceloRab commented Sep 7, 2019

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.9.8-pre.106, on Microsoft Windows [versão 10.0.18362.295], locale pt-BR)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.5)
[√] VS Code (version 1.37.0)
[!] Connected device
! No devices available

! Doctor found issues in 1 category.

@TatsuUkraine
Copy link
Owner

TatsuUkraine commented Sep 7, 2019

@MarceloRab ok, I think I found where problem is. Try to specify ScrollController() in InfiniteList as tmp solution (InfiniteList class has controller property for this). I'm going to investigate this further, but it seems that Flutter doesn't create controller for scroll axis horizontal

@TatsuUkraine
Copy link
Owner

Which is strange, since it creates controller for vertical scroll by default, if it's not specified

@MarceloRab
Copy link
Author

@TatsuUkraine My list is inside a NotificationListener . That's why I don't add a ScrollController (). But I will test as per your recommendation.

@TatsuUkraine
Copy link
Owner

TatsuUkraine commented Sep 7, 2019

@MarceloRab it's just a temp if you need to make it work quickly) I will push new release with fix for this issue tomorrow

@TatsuUkraine
Copy link
Owner

TatsuUkraine commented Sep 7, 2019

@MarceloRab Or you can use this branch for now position-listener-bug

@TatsuUkraine TatsuUkraine added the bug Something isn't working label Sep 7, 2019
@MarceloRab
Copy link
Author

MarceloRab commented Sep 7, 2019

@TatsuUkraine Everything was ok. As used in a PageView, there is no need for horizontal movement. But your orientation of not setting controller = null solved the problem in my tests. Horizontal scrolling worked as expected after the change. Thank you very much. You can close the topic.

@TatsuUkraine TatsuUkraine mentioned this issue Sep 8, 2019
4 tasks
@TatsuUkraine
Copy link
Owner

TatsuUkraine commented Sep 8, 2019

@MarceloRab new version is available (1.2.3) on pub.dart. This version contains fixes for this issue with a horizontal scroll. Also it fixes standalone StickyListItem usage inside SingleChildScrollView.

Also Example project was updated with an example of StickyListItem usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants