Created with <3 with dartpad.dev.
Last active
August 15, 2023 19:41
-
-
Save knaeckeKami/37b57f2148efd55d23e172d11dd2f23c to your computer and use it in GitHub Desktop.
astonishing-spray-1411
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'dart:ui'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_hooks/flutter_hooks.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
scrollBehavior: const MaterialScrollBehavior().copyWith(dragDevices: { | |
PointerDeviceKind.mouse, | |
PointerDeviceKind.touch, | |
PointerDeviceKind.trackpad, | |
PointerDeviceKind.unknown | |
}), | |
home: const Scaffold(body: MyWidget())); | |
} | |
} | |
class MyWidget extends HookWidget { | |
const MyWidget({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
final scrollController = useScrollController(); | |
return Scrollable( | |
controller: scrollController, | |
axisDirection: AxisDirection.right, | |
physics: const AlwaysScrollableScrollPhysics(), | |
viewportBuilder: (context, offsets) => LayoutBuilder( | |
builder: (context, constraints) { | |
offsets.applyViewportDimension(constraints.minWidth); | |
offsets.applyContentDimensions(double.negativeInfinity, double.infinity); | |
return AnimatedBuilder( | |
animation: scrollController, | |
builder: (context, _) => CustomPaint( | |
size: Size(constraints.maxWidth, 500), | |
painter: MyPainter( | |
scrollController.offset, | |
), | |
)); | |
}, | |
), | |
); | |
} | |
} | |
class MyPainter extends CustomPainter { | |
final double offset; | |
MyPainter(this.offset); | |
@override | |
void paint(Canvas canvas, Size size) { | |
// draw graph based on offset | |
// draw a rotating pacman instead for now | |
canvas.translate(size.width / 2, size.height / 2); | |
canvas.rotate(offset / size.width * 2 * pi); | |
canvas.translate(-size.width / 2,- size.height / 2); | |
canvas.drawArc(Rect.fromCenter(center: Offset(size.width / 2, size.height / 2), width: 50, height: 50), 0, 1.75 * pi, true, Paint()..color = Colors.black); | |
} | |
@override | |
bool shouldRepaint(covariant CustomPainter old) => true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment