Skip to content

Instantly share code, notes, and snippets.

@slightfoot
Forked from drexel-ue/scrollable.dart
Created July 23, 2020 15:38
Show Gist options
  • Save slightfoot/2f561504d5ad451b8dede77357dccddf to your computer and use it in GitHub Desktop.
Save slightfoot/2f561504d5ad451b8dede77357dccddf to your computer and use it in GitHub Desktop.
Scrollable(
axisDirection: AxisDirection.right,
controller: _pageController,
physics: const PageScrollPhysics(parent: ClampingScrollPhysics()),
viewportBuilder: (BuildContext context, ViewportOffset offset) {
return LayoutBuilder(
builder: (context, constraints) {
offset.applyViewportDimension(constraints.maxWidth);
offset.applyContentDimensions(0.0, constraints.maxWidth);
return AnimatedBuilder(
animation: offset,
builder: (BuildContext context, Widget child) {
return Transform.translate(
offset: Offset(-offset.pixels, 0.0),
child: child,
);
},
child: ChangeNotifierProvider<ViewportOffset>.value(
value: offset,
child: OverflowBox(
alignment: Alignment.topLeft,
minHeight: constraints.maxHeight,
maxHeight: constraints.maxHeight,
minWidth: constraints.maxWidth * 2,
maxWidth: constraints.maxWidth * 2,
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Page1(),
),
Expanded(
child: Page2(),
),
],
),
),
),
);
},
);
},
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment