Fix a floating snapping SliverAppBar crash (#26101)
This commit is contained in:
parent
cb6fec10dc
commit
4ad3d99b20
@ -393,6 +393,7 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
|
||||
return;
|
||||
if (value == null) {
|
||||
_controller?.dispose();
|
||||
_controller = null;
|
||||
} else {
|
||||
if (_snapConfiguration != null && value.vsync != _snapConfiguration.vsync)
|
||||
_controller?.resync(value.vsync);
|
||||
|
@ -1422,4 +1422,67 @@ void main() {
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
));
|
||||
});
|
||||
|
||||
testWidgets('Changing SliverAppBar snap from true to false', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/17598
|
||||
|
||||
const double appBarHeight = 256.0;
|
||||
bool snap = true;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
SliverAppBar(
|
||||
expandedHeight: appBarHeight,
|
||||
pinned: false,
|
||||
floating: true,
|
||||
snap: snap,
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: const Text('snap=false'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
snap = false;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background: Container(
|
||||
height: appBarHeight,
|
||||
color: Colors.orange,
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
<Widget>[
|
||||
Container(height: 1200.0, color: Colors.teal),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
|
||||
await gesture.moveBy(const Offset(0.0, -100.0));
|
||||
await gesture.up();
|
||||
|
||||
await tester.tap(find.text('snap=false'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
gesture = await tester.startGesture(const Offset(50.0, 400.0));
|
||||
await gesture.moveBy(const Offset(0.0, -100.0));
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user