Skip to content

Instantly share code, notes, and snippets.

@diegoveloper
Created May 30, 2020 03:18
Show Gist options
  • Save diegoveloper/c93924eff6a9765208b0d05c37898154 to your computer and use it in GitHub Desktop.
Save diegoveloper/c93924eff6a9765208b0d05c37898154 to your computer and use it in GitHub Desktop.
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
AnimationController controller;
@override
void initState() {
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
);
controller.addListener(() {
setState(() {});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: <Widget>[
IconButton(
icon: Icon(Icons.add_a_photo),
onPressed: () {
controller.forward(from: 0.0);
},
),
],
),
body: Center(
child: CustomPaint(
painter: MyPainter(controller.value),
child: Container(),
),
),
);
}
}
class MyPainter extends CustomPainter {
double value;
MyPainter(this.value);
@override
void paint(Canvas canvas, Size size) {
double counter = 0.0;
final dotWidth = 20.0;
for (int i = 0; i < size.width; i++) {
final paint = Paint()
..color = Colors.red
..style = PaintingStyle.stroke
..strokeWidth = 10.0;
canvas.drawLine(
Offset(counter, size.height / 2),
Offset((counter + dotWidth) * value, size.height / 2),
paint,
);
counter += (dotWidth * 2);
}
/*
canvas.drawLine(
Offset(0.0, 0.0),
Offset(size.width * value, size.height * value),
paint,
);*/
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment