Last active
September 9, 2021 12:17
-
-
Save doyle-flutter/b54aedd52f9fe636b2c46bff3649de1d to your computer and use it in GitHub Desktop.
Dart 2.14 & Flutter 2.5 : ScrollMetricsNotification
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
| // Doc : https://master-api.flutter.dev/flutter/widgets/ScrollMetricsNotification-class.html | |
| import 'package:flutter/material.dart'; | |
| void main() => runApp(const ScrollMetricsDemo()); | |
| class ScrollMetricsDemo extends StatefulWidget { | |
| const ScrollMetricsDemo({Key? key}) : super(key: key); | |
| @override | |
| State<ScrollMetricsDemo> createState() => ScrollMetricsDemoState(); | |
| } | |
| class ScrollMetricsDemoState extends State<ScrollMetricsDemo> { | |
| double windowSize = 200.0; | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| home: Scaffold( | |
| appBar: AppBar( | |
| title: const Text('ScrollMetrics Demo'), | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| child: const Icon(Icons.add), | |
| onPressed: () => setState(() { | |
| windowSize += 50.0; | |
| }), | |
| ), | |
| body: NotificationListener<ScrollMetricsNotification>( | |
| onNotification: (ScrollMetricsNotification notification) { | |
| ScaffoldMessenger.of(notification.context).showSnackBar( | |
| const SnackBar( | |
| content: Text('Scroll metrics changed!'), | |
| ), | |
| ); | |
| return false; | |
| }, | |
| child: Scrollbar( | |
| isAlwaysShown: true, | |
| child: SizedBox( | |
| height: windowSize, | |
| width: double.infinity, | |
| child: const SingleChildScrollView( | |
| child: FlutterLogo( | |
| size: 300.0, | |
| ), | |
| ), | |
| ), | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment