I am having problem with Flutter List View scrolls speed. Need to get the scroll speed whenever user scrolls list faster or slower. I Want to check the List view scroll speed(Velocity), If user scroll a list faster or slower using scroll controller then it will notify user that scroll speed.
You can try ScrollVelocityListener from this lib
class ExampleApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ScrollVelocityListener(
onVelocity: (velocity) {
// Velocity is in pixels per millisecond
},
child: ListView(
children: [
Container(),
Container(),
Container(),
Container(),
],
),
);
}
}
Related
I'm trying to display a page that has a website on top with some scrollable items below. I would like the website itself to be scrollable (i.e. scroll around the HTML page vertically) as well as the items at the flutter level. Currently I have this which doesn't let you scroll the WebViewWidget at all, it just scrolls with the rest of the scroll items but not within the web page itself:
class MapPage extends StatefulWidget {
MapPage({super.key});
#override
State<MapPage> createState() => _MapPageState();
}
class _MapPageState extends State<MapPage> {
late final WebViewController controller;
#override
void initState() {
super.initState();
// Load a vertically long website that needs scrolling
controller = WebViewController()
..loadRequest(
Uri.parse('https://flutter.dev'),
)
..setJavaScriptMode(JavaScriptMode.unrestricted);
}
#override
Widget build(BuildContext context) {
List<Widget> scrollItems = [];
// TODO: How to make this not part of the scroll view?
scrollItems.add(SizedBox(
width: MediaQuery.of(context).size.width,
height: 400,
child: WebViewWidget(controller: controller)));
// Generate some sample data
var someData = [for (int i = 0; i < 100; i++) i];
for (var entry in someData) {
scrollItems.add(Text("A number: ${entry}"));
}
return CupertinoPageScaffold(
child:
CustomScrollView(semanticChildCount: someData.length + 1, slivers: [
CupertinoSliverNavigationBar(
largeTitle: Text("A page"),
),
SliverSafeArea(
top: false,
minimum: EdgeInsets.only(top: 0),
sliver: SliverToBoxAdapter(
child: CupertinoListSection(topMargin: 0, children: scrollItems),
))
]),
);
}
}
My first instinct was to put the WebViewWidget and CustomScrollView in a Column together but that doesn't work since the Column has infinite height. I'd also like the WebViewWidget to not be fixed on the screen but scroll with the items when the scroll comes from outside the area of the WebViewWidget, as if the scroll gestures there just got ignored by the CustomScrollView and passed to the WebViewWidget but I couldn't find a good way to get this working. Anyone have any pointers to what I can use to get this working?
I am looking for a way to build a widget that creates a scroll controller and contains several widgets that all depend on that scroll controller.
Instead of rendering the whole widget I want to place the widgets that it contains inside a parent widget in their corresponding places whilst still connected to that scroll controller.
EDIT//
In laymen's terms, I want to declare a widget wherever I happen to declare it but not actually render it there. It should render instead in a targeted location but still maintain any state or controllers it obtained or inherited from the position in which it was actually declare. IF this can be done it is probably far simpler than what I have tried to outline here.
//
// Parent Widget
class ParentReceiver extends StatelessWidget {
const ParentReceiver({super.key});
Widget build(BuildContext context){
return Stack(
children: [
Align(
alignment: Alignment.topCenter,
child: // expects to receive InjectWidget's MyHeaderWidget() here.
),
// expects to receive InjectWidget's MyContentWidget() here.
Align(
alignment: Alignment.bottomCenter,
child: // expects to receive InjectWidget's MyFooterWidget() here.
),
]
);
}
}
class InjectWidget extends StatelessWidget {
const InjectWidget({super.key});
Widget build(BuildContext context){
ScrollController scrollController = useScrollController();
// yes that's a hook but it doesn't matter how I got the scroll controller.
return Stack(
children: [
MyHeaderWidget(scrollController: scrollController);
MyContentWidget(scrollController: scrollController);
MyFooterWidget(scrollController: scrollController);
],
);
}
}
class MyContentWidget extends StatelessWidget {
const MyContentWidget({super.key, required scrollController,});
final ScrollController scrollController;
Widget build(BuildContext context){
return ListView(
controller: scrollController,
children: [
etc...
]
);
}
}
So MyHeaderWidget, MyFooterWidget and MyContentWidget all used the scroll controller that was created by InjectWidget. However, InjectWidget is not to render directly. These three individual widgets with their scroll controller intact should be placed into the corresponding areas of the ParentReceiver Widget.
The basic premise behind this is to build entire widgets that respond to controllers but place various component parts of them into the parent view.
Here is my problem.
I would like that by dragging progressively (with my finger for example) up a container (Container) that this one moves following the movement but that a new page (NewPage) towards which I want to navigate is supperposed on the container while following the movement until a certain level when I release, that the page takes all the screen. (Let's say I want to do a Navigator.push but in this sense).
Thank you.
class NewPage extends StatelessWidget {
...
#override
Widget build(BuildContext context) {
return Scaffold(...);
}
}
...
class _MainPageState extends State<MainPage> {
...
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
...
GestureDetector(
child: Positioned(
...
child: Container()
)
)
]
)
);
}
}
Your question is a bit unclear. But try these different navigation techniques.
Hero Animations
PageView - Try this with scrollDirection: Axis.vertical
I am trying to implement a Scroll Widget in Flutter but not able to implement it.
I saw many tutorials but they have implemented scroll widget with ListView or Grid View.
In my case, I have Register page with multiple Text Inputs and Buttons. In this case, my page is not scrolling down please help someone.
div{
Scroll Widget on the Register page.
}
like this
class ExampleScroll extends StatefulWidget {
#override
_ExampleScrollState createState() => _ExampleScrollState();
}
class _ExampleScrollState extends State<ExampleScroll> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(),
),
);
}
}
Please wrap with a SingleChildScrollView Widget.
Like this...
class AppDashBoard extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
child: Text('It Scrollable'),
),
);
}
}
You can use SingleChildScrollView for scrolling like this.
SingleChildScrollView(
child:Column(...)
)
You can use SingleChildScrollView and provide scrolling contents as its child
for more you can find on the documentation
https://api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html
Eg:
SingleChildScrollView(
// scrollable contents as child
child:Column(...)
)
I've been dealing with a strange situation in Flutter that I just can't figure out.
The problem is that when I attempt to use any kind of TextField in any kind of Scrollable Widget, when I tap the TextField for the keyboard to come up, the keyboard pushes the TextField off of the screen. Everything in the Scaffold is just blank.
I can't exactly say for sure what is happening but sometimes it seems as if the keyboard pushes the content of the scrollable view up past the view but other times it seems that there just seems to be a giant white box attached to the top of the keyboard that covers the context. I've done several experiments but I can't pin the exact behavior down.
To be clear, I've tried using SingleChildScrollView and a ListView. The behavior is the same.
I've read through the whole of this thread and tried the workarounds with no success:
https://github.com/flutter/flutter/issues/10826
I've also tried using this workaround:
https://gist.github.com/collinjackson/50172e3547e959cba77e2938f2fe5ff5
However, I am just not sure that I am having the exact same issue as those threads.
Here is a code snippet that demonstrates the problem and some screenshots. Am I just doing something blatantly wrong?
class MakeEntryView extends StatefulWidget {
#override
State<StatefulWidget> createState() => new MakeEntryState();
}
class MakeEntryState extends State<MakeEntryView> {
#override
Widget build(BuildContext context) {
return new Scaffold(
body: new SingleChildScrollView(
child: new Container(
child: new Column(
children: <Widget>[
new TextField(),
new TextField(),
new TextField(),
new TextField(),
new TextField(),
new TextField(),
new TextField(),
],
),
),
)
);
}
#override
void initState() {
super.initState();
}
#override
void dispose() {
super.dispose();
}
}
Before pressing Text Field
After Pressing Text Field
The Scaffold has a properly to deal with this:
Scaffold(
resizeToAvoidBottomPadding: false,
There are rare cases where it doesn't work but that should take care of it.