Skip to content

Instantly share code, notes, and snippets.

@immadisairaj
Last active December 29, 2023 07:08
Show Gist options
  • Save immadisairaj/f8183407888bfd3aaf7ab3b273e330d3 to your computer and use it in GitHub Desktop.
Save immadisairaj/f8183407888bfd3aaf7ab3b273e330d3 to your computer and use it in GitHub Desktop.
List of items (full screen) in vertical scroll that perfectly snaps into place. (#wheel_list_snap)
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: MyWidget(),
),
);
}
}
class MyWidget extends StatelessWidget {
final controller = FixedExtentScrollController();
@override
Widget build(BuildContext context) {
return Scrollbar(
controller: controller,
thumbVisibility: true,
child: ListWheelScrollView(
physics: const FixedExtentScrollPhysics(),
controller: controller,
useMagnifier: true,
magnification: 1.25,
itemExtent: MediaQuery.sizeOf(context).height * 0.8,
children: [
Container(
width: MediaQuery.sizeOf(context).width * 0.8,
color: Colors.red,
child: const Center(child: Text('0')),
),
Container(
width: MediaQuery.sizeOf(context).width * 0.8,
color: Colors.blue,
child: const Center(child: Text('1')),
),
Container(
width: MediaQuery.sizeOf(context).width * 0.8,
color: Colors.green,
child: const Center(child: Text('2')),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment