import 'dart:developer';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late FixedExtentScrollController scrollController;
bool visible = false;
@override
void initState() {
scrollController = FixedExtentScrollController();
super.initState();
}
@override
void dispose() {
scrollController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
floatingActionButton: FloatingActionButton(
child: Icon(visible ? Icons.visibility : Icons.visibility_off),
onPressed: () {
setState(() {
visible = !visible;
});
},
),
body: ListWheelScrollView(
controller: scrollController,
renderChildrenOutsideViewport: false,
clipBehavior: Clip.none,
physics: const FixedExtentScrollPhysics(),
itemExtent: 110,
children: ['A', 'B', 'C', 'D', 'E', 'F', 'G']
.map(
(letter) => Visibility(
visible: visible,
child: GestureDetector(
onTap: () => log('Letter "$letter" is pressed.'),
child: Container(
margin: const EdgeInsets.all(10),
height: 90,
color: Colors.yellow,
child: Center(
child: Text(
letter,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
)
.toList(),
),
);
}
}
Steps to Reproduce
flutter runon the code sampleExpected results: Items correctly rendered. This can be achieved by setting
visible = trueon the first render.Actual results: Items have a half-screen offset. If you drag the list up and down, so items are recreated, they receive the correct offset.
Code sample
Logs
Screenshots