Skip to content

Instantly share code, notes, and snippets.

@creativecreatorormaybenot
Last active September 14, 2019 22:26
Show Gist options
  • Select an option

  • Save creativecreatorormaybenot/ae17db11763dec46a9164055e28949a9 to your computer and use it in GitHub Desktop.

Select an option

Save creativecreatorormaybenot/ae17db11763dec46a9164055e28949a9 to your computer and use it in GitHub Desktop.
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