text
stringlengths 1
474
|
|---|
}
|
Widget _buildTitleAndSubtitle() {
|
return Positioned(
|
left: 20,
|
bottom: 20,
|
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
Text(
|
name,
|
style: const TextStyle(
|
color: Colors.white,
|
fontSize: 20,
|
fontWeight: FontWeight.bold,
|
),
|
),
|
Text(
|
country,
|
style: const TextStyle(
|
color: Colors.white,
|
fontSize: 14,
|
),
|
),
|
],
|
),
|
);
|
}
|
}
|
class ParallaxFlowDelegate extends FlowDelegate {
|
ParallaxFlowDelegate({
|
required this.scrollable,
|
required this.listItemContext,
|
required this.backgroundImageKey,
|
}) : super(repaint: scrollable.position);
|
final ScrollableState scrollable;
|
final BuildContext listItemContext;
|
final GlobalKey backgroundImageKey;
|
@override
|
BoxConstraints getConstraintsForChild(int i, BoxConstraints constraints) {
|
return BoxConstraints.tightFor(
|
width: constraints.maxWidth,
|
);
|
}
|
@override
|
void paintChildren(FlowPaintingContext context) {
|
// Calculate the position of this list item within the viewport.
|
final scrollableBox = scrollable.context.findRenderObject() as RenderBox;
|
final listItemBox = listItemContext.findRenderObject() as RenderBox;
|
final listItemOffset = listItemBox.localToGlobal(
|
listItemBox.size.centerLeft(Offset.zero),
|
ancestor: scrollableBox);
|
// Determine the percent position of this list item within the
|
// scrollable area.
|
final viewportDimension = scrollable.position.viewportDimension;
|
final scrollFraction =
|
(listItemOffset.dy / viewportDimension).clamp(0.0, 1.0);
|
// Calculate the vertical alignment of the background
|
// based on the scroll percent.
|
final verticalAlignment = Alignment(0.0, scrollFraction * 2 - 1);
|
// Convert the background alignment into a pixel offset for
|
// painting purposes.
|
final backgroundSize =
|
(backgroundImageKey.currentContext!.findRenderObject() as RenderBox)
|
.size;
|
final listItemSize = context.size;
|
final childRect =
|
verticalAlignment.inscribe(backgroundSize, Offset.zero & listItemSize);
|
// Paint the background.
|
context.paintChild(
|
0,
|
transform:
|
Transform.translate(offset: Offset(0.0, childRect.top)).transform,
|
);
|
}
|
@override
|
bool shouldRepaint(ParallaxFlowDelegate oldDelegate) {
|
return scrollable != oldDelegate.scrollable ||
|
listItemContext != oldDelegate.listItemContext ||
|
backgroundImageKey != oldDelegate.backgroundImageKey;
|
}
|
}
|
class Parallax extends SingleChildRenderObjectWidget {
|
const Parallax({
|
super.key,
|
required Widget background,
|
}) : super(child: background);
|
@override
|
RenderObject createRenderObject(BuildContext context) {
|
return RenderParallax(scrollable: Scrollable.of(context));
|
}
|
@override
|
void updateRenderObject(
|
BuildContext context, covariant RenderParallax renderObject) {
|
renderObject.scrollable = Scrollable.of(context);
|
}
|
}
|
class ParallaxParentData extends ContainerBoxParentData<RenderBox> {}
|
class RenderParallax extends RenderBox
|
with RenderObjectWithChildMixin<RenderBox>, RenderProxyBoxMixin {
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.