Fix GlowingOverscrollIndicator examples (#155203)
Part of https://github.com/flutter/flutter/issues/130459 This pull request adds tests for the example files shown in the [GlowingOverscrollIndicator](https://api.flutter.dev/flutter/widgets/GlowingOverscrollIndicator-class.html) Flutter API reference documentation.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Flutter code sample for [GlowingOverscrollIndicator].
|
||||
@@ -14,6 +15,8 @@ class GlowingOverscrollIndicatorExampleApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
scrollBehavior: const AlwaysGlow(),
|
||||
theme: ThemeData(colorSchemeSeed: Colors.amber),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('GlowingOverscrollIndicator Sample')),
|
||||
body: const GlowingOverscrollIndicatorExample(),
|
||||
@@ -22,12 +25,37 @@ class GlowingOverscrollIndicatorExampleApp extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
const Set<PointerDeviceKind> allPointers = <PointerDeviceKind>{...PointerDeviceKind.values};
|
||||
|
||||
// Passing this class into the MaterialApp constructor ensures that a
|
||||
// GlowingOverscrollIndicator is created, regardless of the target platform.
|
||||
class AlwaysGlow extends MaterialScrollBehavior {
|
||||
const AlwaysGlow();
|
||||
|
||||
@override
|
||||
Set<PointerDeviceKind> get dragDevices => allPointers;
|
||||
|
||||
@override
|
||||
Widget buildOverscrollIndicator(
|
||||
BuildContext context,
|
||||
Widget child,
|
||||
ScrollableDetails details,
|
||||
) {
|
||||
return GlowingOverscrollIndicator(
|
||||
axisDirection: details.direction,
|
||||
color: Colors.amberAccent,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class GlowingOverscrollIndicatorExample extends StatelessWidget {
|
||||
const GlowingOverscrollIndicatorExample({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double leadingPaintOffset = MediaQuery.of(context).padding.top + AppBar().preferredSize.height;
|
||||
final double leadingPaintOffset = MediaQuery.paddingOf(context).top + kToolbarHeight;
|
||||
|
||||
return NotificationListener<OverscrollIndicatorNotification>(
|
||||
onNotification: (OverscrollIndicatorNotification notification) {
|
||||
if (notification.leading) {
|
||||
@@ -35,17 +63,33 @@ class GlowingOverscrollIndicatorExample extends StatelessWidget {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
child: CustomScrollView(
|
||||
child: const CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
const SliverAppBar(title: Text('Custom PaintOffset')),
|
||||
SliverAppBar(title: Text('Custom PaintOffset')),
|
||||
SliverToBoxAdapter(
|
||||
child: Container(
|
||||
color: Colors.amberAccent,
|
||||
height: 100,
|
||||
child: const Center(child: Text('Glow all day!')),
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(
|
||||
color: Colors.amberAccent,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
child: ColoredBox(
|
||||
color: Colors.grey,
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: 80,
|
||||
child: Center(child: Text('Glow all day!')),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverFillRemaining(
|
||||
child: Icon(
|
||||
Icons.sunny,
|
||||
color: Colors.amberAccent,
|
||||
size: 128,
|
||||
),
|
||||
),
|
||||
const SliverFillRemaining(child: FlutterLogo()),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Flutter code sample for [GlowingOverscrollIndicator].
|
||||
@@ -14,6 +15,8 @@ class GlowingOverscrollIndicatorExampleApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
scrollBehavior: const AlwaysGlow(),
|
||||
theme: ThemeData(colorSchemeSeed: Colors.amber),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('GlowingOverscrollIndicator Sample')),
|
||||
body: const GlowingOverscrollIndicatorExample(),
|
||||
@@ -22,6 +25,31 @@ class GlowingOverscrollIndicatorExampleApp extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
const Set<PointerDeviceKind> allPointers = <PointerDeviceKind>{...PointerDeviceKind.values};
|
||||
|
||||
// Passing this class into the MaterialApp constructor ensures that a
|
||||
// GlowingOverscrollIndicator is created, regardless of the target platform.
|
||||
class AlwaysGlow extends MaterialScrollBehavior {
|
||||
const AlwaysGlow();
|
||||
|
||||
@override
|
||||
Set<PointerDeviceKind> get dragDevices => allPointers;
|
||||
|
||||
@override
|
||||
Widget buildOverscrollIndicator(
|
||||
BuildContext context,
|
||||
Widget child,
|
||||
ScrollableDetails details,
|
||||
) {
|
||||
return GlowingOverscrollIndicator(
|
||||
axisDirection: details.direction,
|
||||
color: Colors.amberAccent,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class GlowingOverscrollIndicatorExample extends StatelessWidget {
|
||||
const GlowingOverscrollIndicatorExample({super.key});
|
||||
|
||||
@@ -33,16 +61,32 @@ class GlowingOverscrollIndicatorExample extends StatelessWidget {
|
||||
SliverAppBar(title: Text('Custom NestedScrollViews')),
|
||||
];
|
||||
},
|
||||
body: CustomScrollView(
|
||||
body: const CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
SliverToBoxAdapter(
|
||||
child: Container(
|
||||
color: Colors.amberAccent,
|
||||
height: 100,
|
||||
child: const Center(child: Text('Glow all day!')),
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(
|
||||
color: Colors.amberAccent,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
child: ColoredBox(
|
||||
color: Colors.grey,
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: 80,
|
||||
child: Center(child: Text('Glow all day!')),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverFillRemaining(
|
||||
child: Icon(
|
||||
Icons.sunny,
|
||||
color: Colors.amberAccent,
|
||||
size: 128,
|
||||
),
|
||||
),
|
||||
const SliverFillRemaining(child: FlutterLogo()),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user