Last active
February 10, 2022 13:54
-
-
Save justinmc/3c58cb125644b230fe66832b0ea541c2 to your computer and use it in GitHub Desktop.
Example of an iOS13-style draggable scrollbar in Flutter
This file contains 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
import 'package:flutter/cupertino.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
static List<Widget> _getList(int length) { | |
final List<Widget> list = List<Widget>(length); | |
for (int i = 0; i < length; i++) { | |
list[i] = _getListItem(i); | |
} | |
return list; | |
} | |
static Widget _getListItem(int i) { | |
return Text('list item $i'); | |
} | |
@override | |
Widget build(BuildContext context) { | |
final ScrollController scrollController = ScrollController(); | |
return CupertinoApp( | |
title: 'Flutter Demo', | |
home: CupertinoPageScaffold( | |
navigationBar: CupertinoNavigationBar( | |
middle: Text('Draggable Scrollbar Demo'), | |
), | |
child: Column( | |
children: <Widget>[ | |
Container( | |
height: 300, | |
child: PrimaryScrollController( | |
controller: scrollController, | |
child: CupertinoScrollbar( | |
controller: scrollController, | |
child: ListView( | |
controller: scrollController, | |
children: _getList(120), | |
), | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like this app.