overscroll_feedback 0.0.1+1
overscroll_feedback: ^0.0.1+1 copied to clipboard
A Flutter ListView that reveals custom feedback when users pull beyond the scroll edge, with optional haptics and callbacks.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:overscroll_feedback/overscroll_feedback.dart';
void main() {
runApp(const OverscrollFeedbackExampleApp());
}
class OverscrollFeedbackExampleApp extends StatelessWidget {
const OverscrollFeedbackExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF2F6FED)),
useMaterial3: true,
),
home: const OverscrollFeedbackDemo(),
);
}
}
class OverscrollFeedbackDemo extends StatefulWidget {
const OverscrollFeedbackDemo({super.key});
@override
State<OverscrollFeedbackDemo> createState() => _OverscrollFeedbackDemoState();
}
class _OverscrollFeedbackDemoState extends State<OverscrollFeedbackDemo> {
int _reachCount = 0;
static const _messages = [
'Welcome aboard',
'Pull gently',
'Keep scrolling',
'Nearly there',
'Now pull past the end',
];
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: colorScheme.surface,
appBar: AppBar(title: const Text('OverscrollFeedback')),
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
child: Text(
'Reach limit callbacks: $_reachCount',
style: Theme.of(context).textTheme.titleMedium,
),
),
Expanded(
child: OverscrollFeedback.strings(
messages: _messages,
itemColor: colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(12),
reachLimitWidget: _EndOfListFeedback(
color: colorScheme.secondaryContainer,
foregroundColor: colorScheme.onSecondaryContainer,
),
onReachLimit: () {
setState(() {
_reachCount += 1;
});
},
),
),
],
),
),
);
}
}
class _EndOfListFeedback extends StatelessWidget {
const _EndOfListFeedback({
required this.color,
required this.foregroundColor,
});
final Color color;
final Color foregroundColor;
@override
Widget build(BuildContext context) {
return Center(
child: DecoratedBox(
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(999),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.touch_app_rounded, size: 18, color: foregroundColor),
const SizedBox(width: 8),
Text(
'You reached the end',
style: TextStyle(
color: foregroundColor,
fontWeight: FontWeight.w700,
),
),
],
),
),
),
);
}
}