Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Last active September 9, 2021 12:17
Show Gist options
  • Save doyle-flutter/b54aedd52f9fe636b2c46bff3649de1d to your computer and use it in GitHub Desktop.
Save doyle-flutter/b54aedd52f9fe636b2c46bff3649de1d to your computer and use it in GitHub Desktop.
Dart 2.14 & Flutter 2.5 : ScrollMetricsNotification
// 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