Home>

I am a beginner. I am writing a Flutter application for Windows. The problem is that the text in the ListView is scrolling too slowly with the mouse roller. I tried overriding ScrollPhysics but it didn't work. Please give me a working way to change the scrolling speed.

Please clarify your specific problem or provide more detailed information on what exactly you need. As it stands, it is difficult to understand exactly what you are asking.

Дух сообщества2021-12-15 00:05:04
  • Answer # 1

    Got an answer on english stackoverflow. I'm copying here, maybe anyone will need it.

    import 'dart: math';
    import 'package: flutter /material.dart';
    import 'package: flutter /rendering.dart';
    void main () {
      runApp (const MyApp ());
    }
    class MyApp extends StatefulWidget {
      const MyApp ({Key? key}): super (key: key);
      @override
      _MyAppState createState ()= >
     _MyAppState ();
    }
    class _MyAppState extends State <
    MyApp >
     {
      @override
      Widget build (BuildContext context) {
        return MaterialApp (
          home: Scaffold (
            backgroundColor: Colors.black,
            body: ScrollViewTest (),
          ),
        );
      }
    }
    class ScrollViewTest extends StatelessWidget {
      static const _extraScrollSpeed ​​= 1000; //your "extra" scroll speed
      final ScrollController _scrollController= ScrollController ();
      //Constructor
      ScrollViewTest ({Key? Key}): super (key: key)
      {
        _scrollController.addListener (() {
          ScrollDirection scrollDirection= _scrollController.position.userScrollDirection;
          if (scrollDirection!= ScrollDirection.idle)
          {
            double scrollEnd= _scrollController.offset + (scrollDirection== ScrollDirection.reverse
                ? _extraScrollSpeed
                : -_extraScrollSpeed);
            scrollEnd= min (
                _scrollController.position.maxScrollExtent,
                max (_scrollController.position.minScrollExtent, scrollEnd));
            _scrollController.jumpTo (scrollEnd);
          }
        });
      }
      @override
      Widget build (BuildContext context)
      {
        return ListView (
          controller: _scrollController,
          children: [Text (
            '' '
            one
            2
            3
            4
            5
            6
            7
            eight
            9
            10
            eleven
            12
            thirteen
            14
            15
            sixteen
            17
            eighteen
            nineteen
            twenty
            21
            22
            23
            24
            25
            26
            27
            28
            29
            thirty
            31
            32
            33
            34
            35
            36
            37
            38
            39
            40
            41
            42
            43
            44
            45
            46
            47
            48
            49
            50
            '' ',
            style: TextStyle (color: Colors.white, fontSize: 30,),
          ),
        ],);
      }
    }
    

    As it stands, your answer is incomprehensible. Please click edit below the post to add more details to help others understand how he answers the question. You can find more information on how to write good answers in the Help.

    Дух сообщества2021-12-15 15:29:02