Skip to content

Instantly share code, notes, and snippets.

@filiph
Created January 6, 2020 19:39
Show Gist options
  • Select an option

  • Save filiph/11279b9906bebff3310cca107211ee11 to your computer and use it in GitHub Desktop.

Select an option

Save filiph/11279b9906bebff3310cca107211ee11 to your computer and use it in GitHub Desktop.
list_wheel_scroll_view
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double _diameterRatio = 2;
double _offAxisFraction = 0;
double _magnification = 1;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ListWheelScrollView demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Spacer(),
SizedBox(
height: 200,
child: ListWheelScrollView(
useMagnifier: _magnification > 1,
magnification: _magnification,
diameterRatio: _diameterRatio,
offAxisFraction: _offAxisFraction,
itemExtent: 50,
children: <Widget>[
for (int i = 0; i < 10; i++) MyItem(index: i + 1)
],
),
),
Spacer(),
Text('offAxisFraction'),
Slider(
value: _offAxisFraction,
onChanged: (newValue) =>
setState(() => _offAxisFraction = newValue),
min: -2,
max: 2,
),
Text('diameterRatio'),
Slider(
value: _diameterRatio,
onChanged: (newValue) =>
setState(() => _diameterRatio = newValue),
min: 0.1,
max: 10,
),
Text('magnification'),
Slider(
value: _magnification,
onChanged: (newValue) =>
setState(() => _magnification = newValue),
min: 1,
max: 3,
),
],
),
),
);
}
}
class MyItem extends StatelessWidget {
final int index;
MyItem({@required this.index, Key key}) : super(key: key);
static const colors = [
Colors.pink,
Colors.indigo,
Colors.grey,
Colors.red,
Colors.blue,
Colors.green,
Colors.yellow,
];
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 16 / 9,
child: Container(
color: colors[index % colors.length],
child: Center(
child: Text(
'$index',
style: TextStyle(color: Colors.white),
)),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment