Reputation:
Problem:
Initially I have disabled ListView
scrolling, and want to enable it after 3 seconds. The moment app launches and you keep scrolling it for like 5 seconds (without lifting your finger off the screen), the ListView
doesn't scroll.
However it should have scrolled because I am enabling scrolling at 3rd second, the console confirms ListView enabled
but still I am not able to scroll it.
Code:
bool _enabled = false; // scrolling disabled initially
@override
void initState() {
super.initState();
Timer(Duration(seconds: 3), () {
print("Scrolling enabled");
setState(() => _enabled = true); // scrolling enabled after 3 seconds
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
physics: _enabled ? ClampingScrollPhysics() : NeverScrollableScrollPhysics(),
itemBuilder: (_, i) => ListTile(title: Text("Item $i")),
),
);
}
Upvotes: 3
Views: 6130
Reputation: 10953
Here is a workaround for this:
final _scrollController = ScrollController();
var _firstScroll = true;
bool _enabled = false;
@override
void initState() {
super.initState();
Timer(Duration(seconds: 3), () {
setState(() => _enabled = true);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: GestureDetector(
onVerticalDragUpdate: (details) {
if (_enabled && _firstScroll) {
_scrollController
.jumpTo(_scrollController.position.pixels - details.delta.dy);
}
},
onVerticalDragEnd: (_) {
if (_enabled) _firstScroll = false;
},
child: AbsorbPointer(
absorbing: !_enabled,
child: ListView.builder(
controller: _scrollController,
physics: ClampingScrollPhysics(),
itemBuilder: (_, i) => ListTile(title: Text("Item $i")),
),
),
),
);
}
Upvotes: 1
Reputation: 139
try this out...
class _blabla extends State<blabla> {
Timer _timer;
}
@override
void initState() {
super.initState();
bool _enabled = false;
);
}
_blablaState() {
_timer = new Timer(const Duration(seconds: 3), () {
setState(() => _enabled = true);
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
physics: _enabled ? ClampingScrollPhysics() : NeverScrollableScrollPhysics(),
itemBuilder: (_, i) => ListTile(title: Text("Item $i")),
),
);
}
@override
void dispose() {
super.dispose();
_timer.cancel();
}
I would also try with physics disabled to see if it makes a difference. There may be a conflict.
Upvotes: 1