mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Primary scroll view support for SingleChildScrollView (#8437)
This commit is contained in:
parent
f60410fa9d
commit
c8c37fcc85
@ -8,6 +8,7 @@ import 'package:flutter/rendering.dart';
|
||||
|
||||
import 'basic.dart';
|
||||
import 'framework.dart';
|
||||
import 'primary_scroll_controller.dart';
|
||||
import 'scroll_controller.dart';
|
||||
import 'scroll_physics.dart';
|
||||
import 'scrollable.dart';
|
||||
@ -42,11 +43,17 @@ class SingleChildScrollView extends StatelessWidget {
|
||||
this.scrollDirection: Axis.vertical,
|
||||
this.reverse: false,
|
||||
this.padding,
|
||||
this.primary: false,
|
||||
this.physics,
|
||||
this.controller,
|
||||
this.child,
|
||||
}) : super(key: key) {
|
||||
assert(scrollDirection != null);
|
||||
assert(primary != null);
|
||||
assert(controller == null || !primary,
|
||||
'Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. '
|
||||
'You cannot both set primary to true and pass an explicit controller.'
|
||||
);
|
||||
}
|
||||
|
||||
final Axis scrollDirection;
|
||||
@ -57,6 +64,8 @@ class SingleChildScrollView extends StatelessWidget {
|
||||
|
||||
final ScrollController controller;
|
||||
|
||||
final bool primary;
|
||||
|
||||
final ScrollPhysics physics;
|
||||
|
||||
final Widget child;
|
||||
@ -80,7 +89,7 @@ class SingleChildScrollView extends StatelessWidget {
|
||||
contents = new Padding(padding: padding, child: contents);
|
||||
return new Scrollable(
|
||||
axisDirection: axisDirection,
|
||||
controller: controller,
|
||||
controller: controller ?? (primary ? PrimaryScrollController.of(context) : null),
|
||||
physics: physics,
|
||||
viewportBuilder: (BuildContext context, ViewportOffset offset) {
|
||||
return new _SingleChildViewport(
|
||||
|
@ -76,6 +76,26 @@ void main() {
|
||||
expect(scrollable.position, const isInstanceOf<TestScrollPosition>());
|
||||
});
|
||||
|
||||
testWidgets('Sets PrimaryScrollController when primary', (WidgetTester tester) async {
|
||||
ScrollController primaryScrollController = new ScrollController();
|
||||
await tester.pumpWidget(new PrimaryScrollController(
|
||||
controller: primaryScrollController,
|
||||
child: new SingleChildScrollView(
|
||||
primary: true,
|
||||
child: new Container(
|
||||
height: 2000.0,
|
||||
decoration: const BoxDecoration(
|
||||
backgroundColor: const Color(0xFF00FF00),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
Scrollable scrollable = tester.widget(find.byType(Scrollable));
|
||||
expect(scrollable.controller, primaryScrollController);
|
||||
});
|
||||
|
||||
|
||||
testWidgets('Changing scroll controller inside dirty layout builder does not assert', (WidgetTester tester) async {
|
||||
ScrollController controller = new ScrollController();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user