Last active
March 12, 2025 14:00
-
-
Save maheshj01/ceefe22821e0ca8783669a06ad9a9f0b to your computer and use it in GitHub Desktop.
Flutter Horizontal Listwheel Scroll View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | |
// for details. All rights reserved. Use of this source code is governed by a | |
// BSD-style license that can be found in the LICENSE file. | |
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | |
// for details. All rights reserved. Use of this source code is governed by a | |
// BSD-style license that can be found in the LICENSE file. | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({super.key, required this.title}); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
double itemWidth = 60.0; | |
int itemCount = 100; | |
int selected = 50; | |
final _scrollController = FixedExtentScrollController(initialItem: 50); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: RotatedBox( | |
quarterTurns: -1, | |
child: ListWheelScrollView( | |
magnification: 2.0, | |
onSelectedItemChanged: (x) { | |
setState(() { | |
selected = x; | |
}); | |
}, | |
controller: _scrollController, | |
itemExtent: itemWidth, | |
children: List.generate( | |
itemCount, | |
(x) => RotatedBox( | |
quarterTurns: 1, | |
child: AnimatedContainer( | |
duration: Duration(milliseconds: 400), | |
width: x == selected ? 60 : 50, | |
height: x == selected ? 60 : 50, | |
alignment: Alignment.center, | |
decoration: BoxDecoration( | |
color: x == selected ? Colors.red : Colors.grey, | |
shape: BoxShape.circle), | |
child: Text('$x')))), | |
))), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment