Last active
September 14, 2019 22:26
-
-
Save creativecreatorormaybenot/ae17db11763dec46a9164055e28949a9 to your computer and use it in GitHub Desktop.
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
| import 'package:flutter_web/material.dart'; | |
| import 'package:flutter_web_ui/ui.dart' as ui; | |
| void main() async { | |
| await ui.webOnlyInitializePlatform(); | |
| double position = 0; | |
| runApp( | |
| MaterialApp( | |
| home: StatefulBuilder( | |
| builder: (context, setState) => Scaffold( | |
| body: ScrollDemo(position: (pos) => setState(() => position = pos)), | |
| floatingActionButton: Padding( | |
| padding: const EdgeInsets.only(bottom: 48), | |
| child: FloatingActionButton.extended( | |
| label: Text('Extent after: $position'), onPressed: () {}), | |
| ), | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| class ScrollDemo extends StatefulWidget { | |
| final void Function(double pos) position; | |
| const ScrollDemo({ | |
| Key key, | |
| this.position, | |
| }) : super(key: key); | |
| @override | |
| State createState() => _ScrollDemoState(); | |
| } | |
| class _ScrollDemoState extends State<ScrollDemo> { | |
| @override | |
| void didChangeDependencies() { | |
| PrimaryScrollController.of(context).removeListener(log); | |
| PrimaryScrollController.of(context).addListener(log); | |
| super.didChangeDependencies(); | |
| } | |
| void log() => | |
| widget.position(PrimaryScrollController.of(context).position.extentAfter); | |
| @override | |
| Widget build(BuildContext context) => NestedScrollView( | |
| headerSliverBuilder: (_, __) => <Widget>[ | |
| const SliverAppBar( | |
| title: Text('Title'), | |
| ) | |
| ], | |
| body: RefreshIndicator( | |
| onRefresh: () => Future.value(null), | |
| child: CustomScrollView( | |
| slivers: <Widget>[ | |
| SliverList( | |
| delegate: SliverChildListDelegate(<Widget>[ | |
| for (int i = 0; i < 99; i++) | |
| ListTile( | |
| leading: Text(i.toString()), | |
| ) | |
| ])), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment